Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(118)

Side by Side Diff: net/dns/dns_response.cc

Issue 15326002: Fix bug in InitParseWithoutQuestion (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | net/dns/dns_response_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 : io_buffer_(new IOBufferWithSize(length)), 155 : io_buffer_(new IOBufferWithSize(length)),
156 parser_(io_buffer_->data(), length, answer_offset) { 156 parser_(io_buffer_->data(), length, answer_offset) {
157 DCHECK(data); 157 DCHECK(data);
158 memcpy(io_buffer_->data(), data, length); 158 memcpy(io_buffer_->data(), data, length);
159 } 159 }
160 160
161 DnsResponse::~DnsResponse() { 161 DnsResponse::~DnsResponse() {
162 } 162 }
163 163
164 bool DnsResponse::InitParse(int nbytes, const DnsQuery& query) { 164 bool DnsResponse::InitParse(int nbytes, const DnsQuery& query) {
165 DCHECK_GE(nbytes, 0);
165 // Response includes query, it should be at least that size. 166 // Response includes query, it should be at least that size.
166 if (nbytes < query.io_buffer()->size() || nbytes >= io_buffer_->size()) 167 if (nbytes < query.io_buffer()->size() || nbytes >= io_buffer_->size())
167 return false; 168 return false;
168 169
169 // Match the query id. 170 // Match the query id.
170 if (base::NetToHost16(header()->id) != query.id()) 171 if (base::NetToHost16(header()->id) != query.id())
171 return false; 172 return false;
172 173
173 // Match question count. 174 // Match question count.
174 if (base::NetToHost16(header()->qdcount) != 1) 175 if (base::NetToHost16(header()->qdcount) != 1)
175 return false; 176 return false;
176 177
177 // Match the question section. 178 // Match the question section.
178 const size_t hdr_size = sizeof(dns_protocol::Header); 179 const size_t hdr_size = sizeof(dns_protocol::Header);
179 const base::StringPiece question = query.question(); 180 const base::StringPiece question = query.question();
180 if (question != base::StringPiece(io_buffer_->data() + hdr_size, 181 if (question != base::StringPiece(io_buffer_->data() + hdr_size,
181 question.size())) { 182 question.size())) {
182 return false; 183 return false;
183 } 184 }
184 185
185 // Construct the parser. 186 // Construct the parser.
186 parser_ = DnsRecordParser(io_buffer_->data(), 187 parser_ = DnsRecordParser(io_buffer_->data(),
187 nbytes, 188 nbytes,
188 hdr_size + question.size()); 189 hdr_size + question.size());
189 return true; 190 return true;
190 } 191 }
191 192
192 bool DnsResponse::InitParseWithoutQuery(int nbytes) { 193 bool DnsResponse::InitParseWithoutQuery(int nbytes) {
193 if (nbytes >= io_buffer_->size()) 194 DCHECK_GE(nbytes, 0);
195
196 size_t hdr_size = sizeof(dns_protocol::Header);
197
198 if (nbytes < static_cast<int>(hdr_size) || nbytes >= io_buffer_->size())
194 return false; 199 return false;
195 200
196 size_t hdr_size = sizeof(dns_protocol::Header);
197 parser_ = DnsRecordParser( 201 parser_ = DnsRecordParser(
198 io_buffer_->data(), nbytes, hdr_size); 202 io_buffer_->data(), nbytes, hdr_size);
199 203
200 unsigned qdcount = base::NetToHost16(header()->qdcount); 204 unsigned qdcount = base::NetToHost16(header()->qdcount);
201 for (unsigned i = 0; i < qdcount; ++i) { 205 for (unsigned i = 0; i < qdcount; ++i) {
202 if (!parser_.SkipQuestion()) { 206 if (!parser_.SkipQuestion()) {
203 parser_ = DnsRecordParser(); // Make parser invalid again. 207 parser_ = DnsRecordParser(); // Make parser invalid again.
204 return false; 208 return false;
205 } 209 }
206 } 210 }
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 323
320 // getcanonname in eglibc returns the first owner name of an A or AAAA RR. 324 // 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. 325 // If the response passed all the checks so far, then |expected_name| is it.
322 *addr_list = AddressList::CreateFromIPAddressList(ip_addresses, 326 *addr_list = AddressList::CreateFromIPAddressList(ip_addresses,
323 expected_name); 327 expected_name);
324 *ttl = base::TimeDelta::FromSeconds(ttl_sec); 328 *ttl = base::TimeDelta::FromSeconds(ttl_sec);
325 return DNS_PARSE_OK; 329 return DNS_PARSE_OK;
326 } 330 }
327 331
328 } // namespace net 332 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/dns/dns_response_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698