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

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

Issue 10546081: [net/dns] If the only name server is 0.0.0.0:53 assume DnsConfig is invalid. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Reject when any nameserver is 0.0.0.0 Created 8 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | net/dns/dns_config_service_posix_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_config_service_posix.h" 5 #include "net/dns/dns_config_service_posix.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/file_path.h" 11 #include "base/file_path.h"
12 #include "base/file_util.h" 12 #include "base/file_util.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "net/base/ip_endpoint.h" 14 #include "net/base/ip_endpoint.h"
15 #include "net/base/net_util.h" 15 #include "net/base/net_util.h"
16 #include "net/dns/dns_hosts.h" 16 #include "net/dns/dns_hosts.h"
17 #include "net/dns/dns_protocol.h"
17 #include "net/dns/serial_worker.h" 18 #include "net/dns/serial_worker.h"
18 19
19 namespace net { 20 namespace net {
20 21
21 namespace { 22 namespace {
22 23
23 #ifndef _PATH_RESCONF // Normally defined in <resolv.h> 24 #ifndef _PATH_RESCONF // Normally defined in <resolv.h>
24 #define _PATH_RESCONF "/etc/resolv.conf" 25 #define _PATH_RESCONF "/etc/resolv.conf"
25 #endif 26 #endif
26 27
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 } 195 }
195 if (!ipe.FromSockAddr(addr, addr_len)) 196 if (!ipe.FromSockAddr(addr, addr_len))
196 return false; 197 return false;
197 dns_config->nameservers.push_back(ipe); 198 dns_config->nameservers.push_back(ipe);
198 } 199 }
199 #else // !(defined(OS_LINUX) || defined(OS_MACOSX) || defined(OS_FREEBSD)) 200 #else // !(defined(OS_LINUX) || defined(OS_MACOSX) || defined(OS_FREEBSD))
200 DCHECK_LE(res.nscount, MAXNS); 201 DCHECK_LE(res.nscount, MAXNS);
201 for (int i = 0; i < res.nscount; ++i) { 202 for (int i = 0; i < res.nscount; ++i) {
202 IPEndPoint ipe; 203 IPEndPoint ipe;
203 if (!ipe.FromSockAddr( 204 if (!ipe.FromSockAddr(
204 reinterpret_cast<const struct sockaddr*>(&res.nsaddr_list[i]), 205 reinterpret_cast<const struct sockaddr*>(&res.nsaddr_list[i]),
205 sizeof res.nsaddr_list[i])) { 206 sizeof res.nsaddr_list[i])) {
206 return false; 207 return false;
207 } 208 }
208 dns_config->nameservers.push_back(ipe); 209 dns_config->nameservers.push_back(ipe);
209 } 210 }
210 #endif 211 #endif
211 212
212 dns_config->search.clear(); 213 dns_config->search.clear();
213 for (int i = 0; (i < MAXDNSRCH) && res.dnsrch[i]; ++i) { 214 for (int i = 0; (i < MAXDNSRCH) && res.dnsrch[i]; ++i) {
214 dns_config->search.push_back(std::string(res.dnsrch[i])); 215 dns_config->search.push_back(std::string(res.dnsrch[i]));
215 } 216 }
216 217
217 dns_config->ndots = res.ndots; 218 dns_config->ndots = res.ndots;
218 dns_config->timeout = base::TimeDelta::FromSeconds(res.retrans); 219 dns_config->timeout = base::TimeDelta::FromSeconds(res.retrans);
219 dns_config->attempts = res.retry; 220 dns_config->attempts = res.retry;
220 #if defined(RES_ROTATE) 221 #if defined(RES_ROTATE)
221 dns_config->rotate = res.options & RES_ROTATE; 222 dns_config->rotate = res.options & RES_ROTATE;
222 #endif 223 #endif
223 dns_config->edns0 = res.options & RES_USE_EDNS0; 224 dns_config->edns0 = res.options & RES_USE_EDNS0;
224 225
226 // If any name server is 0.0.0.0, assume the configuration is invalid.
227 // TODO(szym): Measure how often this happens. http://crbug.com/125599
228 const IPAddressNumber kEmptyAddress(kIPv4AddressSize);
229 for (unsigned i = 0; i < dns_config->nameservers.size(); ++i)
230 if (dns_config->nameservers[i].address() == kEmptyAddress)
231 return false;
225 return true; 232 return true;
226 } 233 }
227 #endif // !defined(OS_ANDROID) 234 #endif // !defined(OS_ANDROID)
228 235
229 } // namespace internal 236 } // namespace internal
230 237
231 // static 238 // static
232 scoped_ptr<DnsConfigService> DnsConfigService::CreateSystemService() { 239 scoped_ptr<DnsConfigService> DnsConfigService::CreateSystemService() {
233 return scoped_ptr<DnsConfigService>(new internal::DnsConfigServicePosix()); 240 return scoped_ptr<DnsConfigService>(new internal::DnsConfigServicePosix());
234 } 241 }
235 242
236 } // namespace net 243 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/dns/dns_config_service_posix_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698