Index: net/dns/dns_response.cc |
diff --git a/net/dns/dns_response.cc b/net/dns/dns_response.cc |
index 625e7c041dc0ddfc0eb5c02dc650b22d58fba7d2..ce469cc68d0b9eb522c5c858c8564f8a89a96ab6 100644 |
--- a/net/dns/dns_response.cc |
+++ b/net/dns/dns_response.cc |
@@ -127,6 +127,20 @@ bool DnsRecordParser::ReadRecord(DnsResourceRecord* out) { |
return false; |
} |
+bool DnsRecordParser::SkipQuestion() { |
+ size_t consumed = ReadName(cur_, NULL); |
+ if (!consumed) |
+ return false; |
+ |
+ const char* next = cur_ + consumed + 2 * sizeof(uint16); |
szym
2013/04/23 14:06:41
Please, leave the comment QTYPE + QCLASS explainin
Noam Samuel
2013/04/23 17:56:31
Done.
|
+ if (static_cast<unsigned>(next - packet_) > length_) |
szym
2013/04/23 14:06:41
This comparison is unsafe, it should instead be:
Noam Samuel
2013/04/23 17:56:31
Done.
|
+ return false; |
+ |
+ cur_ = next; |
+ |
+ return true; |
+} |
+ |
DnsResponse::DnsResponse() |
: io_buffer_(new IOBufferWithSize(dns_protocol::kMaxUDPSize + 1)) { |
} |
@@ -175,6 +189,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. |
+ return false; |
+ } |
+ } |
+ |
+ return true; |
+} |
+ |
bool DnsResponse::IsValid() const { |
return parser_.IsValid(); |
} |