Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/dns/dns_response.h" | 5 #include "net/dns/dns_response.h" |
| 6 | 6 |
| 7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
| 8 #include "base/sys_byteorder.h" | 8 #include "base/sys_byteorder.h" |
| 9 #include "net/base/address_list.h" | 9 #include "net/base/address_list.h" |
| 10 #include "net/base/big_endian.h" | 10 #include "net/base/big_endian.h" |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 183 } | 183 } |
| 184 | 184 |
| 185 // Construct the parser. | 185 // Construct the parser. |
| 186 parser_ = DnsRecordParser(io_buffer_->data(), | 186 parser_ = DnsRecordParser(io_buffer_->data(), |
| 187 nbytes, | 187 nbytes, |
| 188 hdr_size + question.size()); | 188 hdr_size + question.size()); |
| 189 return true; | 189 return true; |
| 190 } | 190 } |
| 191 | 191 |
| 192 bool DnsResponse::InitParseWithoutQuery(int nbytes) { | 192 bool DnsResponse::InitParseWithoutQuery(int nbytes) { |
| 193 if (nbytes >= io_buffer_->size()) | 193 if (nbytes < 0 || |
|
szym
2013/05/17 20:43:21
nbytes < 0 is an error. You should probably DCHECK
Noam Samuel
2013/05/17 20:52:44
Done.
| |
| 194 (unsigned)nbytes < sizeof(dns_protocol::Header) || | |
| 195 nbytes >= io_buffer_->size()) | |
| 194 return false; | 196 return false; |
| 195 | 197 |
| 196 size_t hdr_size = sizeof(dns_protocol::Header); | 198 size_t hdr_size = sizeof(dns_protocol::Header); |
| 197 parser_ = DnsRecordParser( | 199 parser_ = DnsRecordParser( |
| 198 io_buffer_->data(), nbytes, hdr_size); | 200 io_buffer_->data(), nbytes, hdr_size); |
| 199 | 201 |
| 200 unsigned qdcount = base::NetToHost16(header()->qdcount); | 202 unsigned qdcount = base::NetToHost16(header()->qdcount); |
| 201 for (unsigned i = 0; i < qdcount; ++i) { | 203 for (unsigned i = 0; i < qdcount; ++i) { |
| 202 if (!parser_.SkipQuestion()) { | 204 if (!parser_.SkipQuestion()) { |
| 203 parser_ = DnsRecordParser(); // Make parser invalid again. | 205 parser_ = DnsRecordParser(); // Make parser invalid again. |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 319 | 321 |
| 320 // getcanonname in eglibc returns the first owner name of an A or AAAA RR. | 322 // getcanonname in eglibc returns the first owner name of an A or AAAA RR. |
| 321 // If the response passed all the checks so far, then |expected_name| is it. | 323 // If the response passed all the checks so far, then |expected_name| is it. |
| 322 *addr_list = AddressList::CreateFromIPAddressList(ip_addresses, | 324 *addr_list = AddressList::CreateFromIPAddressList(ip_addresses, |
| 323 expected_name); | 325 expected_name); |
| 324 *ttl = base::TimeDelta::FromSeconds(ttl_sec); | 326 *ttl = base::TimeDelta::FromSeconds(ttl_sec); |
| 325 return DNS_PARSE_OK; | 327 return DNS_PARSE_OK; |
| 326 } | 328 } |
| 327 | 329 |
| 328 } // namespace net | 330 } // namespace net |
| OLD | NEW |