Index: net/dns/dns_response.cc |
diff --git a/net/dns/dns_response.cc b/net/dns/dns_response.cc |
index 625e7c041dc0ddfc0eb5c02dc650b22d58fba7d2..75a699782a3ab0cfc912714b3d5fe62063c86c13 100644 |
--- a/net/dns/dns_response.cc |
+++ b/net/dns/dns_response.cc |
@@ -127,6 +127,16 @@ bool DnsRecordParser::ReadRecord(DnsResourceRecord* out) { |
return false; |
} |
+bool DnsRecordParser::SkipQuestion() { |
+ size_t consumed = ReadName(cur_, NULL); |
+ if (!consumed) |
+ return false; |
+ cur_ += consumed + 2 * sizeof(uint16); // QTYPE + QCLASS |
+ if (static_cast<unsigned>(cur_ - packet_) > length_) |
+ return false; |
+ return true; |
+} |
+ |
DnsResponse::DnsResponse() |
: io_buffer_(new IOBufferWithSize(dns_protocol::kMaxUDPSize + 1)) { |
} |
@@ -175,6 +185,25 @@ bool DnsResponse::InitParse(int nbytes, const DnsQuery& query) { |
return true; |
} |
+bool DnsResponse::InitParseWithoutQuery(int nbytes) { |
+ if (nbytes >= io_buffer_->size()) |
+ return false; |
+ |
+ size_t hdr_size = sizeof(dns_protocol::Header); |
+ parser_ = DnsRecordParser( |
+ io_buffer_->data(), nbytes, hdr_size); |
+ |
+ unsigned qdcount = base::NetToHost16(header()->qdcount); |
+ for (unsigned i = 0; i < qdcount; ++i) { |
+ if (!parser_.SkipQuestion()) { |
+ parser_ = DnsRecordParser(); // Make parser invalid again |
szym
2013/04/18 19:12:34
nit: '.' at end of sentence.
|
+ return false; |
+ } |
+ } |
+ |
+ return true; |
+} |
+ |
bool DnsResponse::IsValid() const { |
return parser_.IsValid(); |
} |
@@ -293,3 +322,4 @@ DnsResponse::Result DnsResponse::ParseToAddressList( |
} |
} // namespace net |
+ |
szym
2013/04/18 19:12:34
Ditto.
Noam Samuel
2013/04/19 22:13:23
Done.
|