Chromium Code Reviews| Index: net/dns/dns_response.cc |
| diff --git a/net/dns/dns_response.cc b/net/dns/dns_response.cc |
| index 625e7c041dc0ddfc0eb5c02dc650b22d58fba7d2..f0b24bbc3f26f46a5bbabb1aa2390c36aacaa21e 100644 |
| --- a/net/dns/dns_response.cc |
| +++ b/net/dns/dns_response.cc |
| @@ -4,6 +4,8 @@ |
| #include "net/dns/dns_response.h" |
| +#include <climits> |
| + |
| #include "base/string_util.h" |
| #include "base/sys_byteorder.h" |
| #include "net/base/address_list.h" |
| @@ -175,6 +177,19 @@ bool DnsResponse::InitParse(int nbytes, const DnsQuery& query) { |
| return true; |
| } |
| +bool DnsResponse::InitParseNoQuery(int nbytes) { |
|
gene
2013/04/16 21:55:22
nit: you may consider naming this InitParse() as w
Noam Samuel
2013/04/16 23:28:19
Done.
|
| + if (nbytes >= io_buffer_->size()) |
| + return false; |
| + |
| + const size_t hdr_size = sizeof(dns_protocol::Header); |
| + |
| + // Construct the parser. |
| + parser_ = DnsRecordParser(io_buffer_->data(), |
| + nbytes, |
| + hdr_size + GetQuestionSectionSize()); |
| + return true; |
| +} |
| + |
| bool DnsResponse::IsValid() const { |
| return parser_.IsValid(); |
| } |
| @@ -217,6 +232,43 @@ std::string DnsResponse::GetDottedName() const { |
| return DNSDomainToString(qname()); |
| } |
| +size_t DnsResponse::GetQuestionSectionSize() const { |
|
gene
2013/04/16 21:55:22
nit: You may consider changing this function to Ge
Noam Samuel
2013/04/16 23:28:19
Done.
|
| + uint16 qdcount = base::NetToHost16(header()->qdcount); |
| + size_t hdr_size = sizeof(dns_protocol::Header); |
| + const char* data = io_buffer_->data(); |
| + size_t data_size = io_buffer_->size(); |
| + size_t pos = hdr_size; |
| + |
| + for (uint16 i = 0; i < qdcount; i++) { |
| + while (pos < data_size && data[pos]) { |
|
gene
2013/04/16 21:55:22
data[pos] -> data[pos] != 0
you can make it more e
Noam Samuel
2013/04/16 23:28:19
Done.
|
| + // Traversal and checks adapted from DNSDomainToString. |
| + |
| + // Handling pointers, which have both high bits set and an extra |
| + // byte trailing them to indicate a location in the buffer. |
| + if (static_cast<unsigned>(data[pos]) >= 192) { |
|
gene
2013/04/16 21:55:22
could you please make a new variable
usigned txt_l
|
| + pos+=2; |
| + continue; |
| + } |
| + |
| +#if CHAR_MIN < 0 |
| + if (data[pos] < 0) |
| + return 0; |
| +#endif |
| + if (data[pos] > 63) { |
| + return 0; |
| + } |
| + |
| + if (static_cast<int>(data[pos] + pos + 1 > data_size)) |
|
gene
2013/04/16 21:55:22
why do you need static_cast here?
btw, you may mov
Noam Samuel
2013/04/16 23:28:19
Done.
|
| + return 0; |
| + |
| + pos += data[pos]+1; |
|
gene
2013/04/16 21:55:22
need spaces aroud +
Noam Samuel
2013/04/16 23:28:19
Done.
|
| + } |
| + |
| + pos += 5; // 2 for qtype, 2 for qclass, 1 for null char |
|
gene
2013/04/16 21:55:22
Comment is a bit misleading, I think it should be
Noam Samuel
2013/04/16 23:28:19
Done.
|
| + } |
| + return pos - hdr_size; |
| +} |
| + |
| DnsRecordParser DnsResponse::Parser() const { |
| DCHECK(parser_.IsValid()); |
| // Return a copy of the parser. |