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

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

Issue 435603008: Fix crash when trying to connect to an IPv6 IP via a SOCKS4 proxy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Response to ttuttle's comments. Created 6 years, 4 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/host_resolver_impl_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/host_resolver_impl.h" 5 #include "net/dns/host_resolver_impl.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <Winsock2.h> 8 #include <Winsock2.h>
9 #elif defined(OS_POSIX) 9 #elif defined(OS_POSIX)
10 #include <netdb.h> 10 #include <netdb.h>
(...skipping 17 matching lines...) Expand all
28 #include "base/strings/string_util.h" 28 #include "base/strings/string_util.h"
29 #include "base/strings/utf_string_conversions.h" 29 #include "base/strings/utf_string_conversions.h"
30 #include "base/threading/worker_pool.h" 30 #include "base/threading/worker_pool.h"
31 #include "base/time/time.h" 31 #include "base/time/time.h"
32 #include "base/values.h" 32 #include "base/values.h"
33 #include "net/base/address_family.h" 33 #include "net/base/address_family.h"
34 #include "net/base/address_list.h" 34 #include "net/base/address_list.h"
35 #include "net/base/dns_reloader.h" 35 #include "net/base/dns_reloader.h"
36 #include "net/base/dns_util.h" 36 #include "net/base/dns_util.h"
37 #include "net/base/host_port_pair.h" 37 #include "net/base/host_port_pair.h"
38 #include "net/base/ip_endpoint.h"
38 #include "net/base/net_errors.h" 39 #include "net/base/net_errors.h"
39 #include "net/base/net_log.h" 40 #include "net/base/net_log.h"
40 #include "net/base/net_util.h" 41 #include "net/base/net_util.h"
41 #include "net/dns/address_sorter.h" 42 #include "net/dns/address_sorter.h"
42 #include "net/dns/dns_client.h" 43 #include "net/dns/dns_client.h"
43 #include "net/dns/dns_config_service.h" 44 #include "net/dns/dns_config_service.h"
44 #include "net/dns/dns_protocol.h" 45 #include "net/dns/dns_protocol.h"
45 #include "net/dns/dns_response.h" 46 #include "net/dns/dns_response.h"
46 #include "net/dns/dns_transaction.h" 47 #include "net/dns/dns_transaction.h"
47 #include "net/dns/host_resolver_proc.h" 48 #include "net/dns/host_resolver_proc.h"
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 RandIntCallback(), 176 RandIntCallback(),
176 net_log.net_log(), 177 net_log.net_log(),
177 net_log.source())); 178 net_log.source()));
178 int rv = socket->Connect(IPEndPoint(dest, 53)); 179 int rv = socket->Connect(IPEndPoint(dest, 53));
179 if (rv != OK) 180 if (rv != OK)
180 return false; 181 return false;
181 IPEndPoint endpoint; 182 IPEndPoint endpoint;
182 rv = socket->GetLocalAddress(&endpoint); 183 rv = socket->GetLocalAddress(&endpoint);
183 if (rv != OK) 184 if (rv != OK)
184 return false; 185 return false;
185 DCHECK(endpoint.GetFamily() == ADDRESS_FAMILY_IPV6); 186 DCHECK_EQ(ADDRESS_FAMILY_IPV6, endpoint.GetFamily());
186 const IPAddressNumber& address = endpoint.address(); 187 const IPAddressNumber& address = endpoint.address();
187 bool is_link_local = (address[0] == 0xFE) && ((address[1] & 0xC0) == 0x80); 188 bool is_link_local = (address[0] == 0xFE) && ((address[1] & 0xC0) == 0x80);
188 if (is_link_local) 189 if (is_link_local)
189 return false; 190 return false;
190 const uint8 kTeredoPrefix[] = { 0x20, 0x01, 0, 0 }; 191 const uint8 kTeredoPrefix[] = { 0x20, 0x01, 0, 0 };
191 bool is_teredo = std::equal(kTeredoPrefix, 192 bool is_teredo = std::equal(kTeredoPrefix,
192 kTeredoPrefix + arraysize(kTeredoPrefix), 193 kTeredoPrefix + arraysize(kTeredoPrefix),
193 address.begin()); 194 address.begin());
194 if (is_teredo) 195 if (is_teredo)
195 return false; 196 return false;
(...skipping 1829 matching lines...) Expand 10 before | Expand all | Expand 10 after
2025 DCHECK(addresses); 2026 DCHECK(addresses);
2026 DCHECK(net_error); 2027 DCHECK(net_error);
2027 IPAddressNumber ip_number; 2028 IPAddressNumber ip_number;
2028 if (!ParseIPLiteralToNumber(key.hostname, &ip_number)) 2029 if (!ParseIPLiteralToNumber(key.hostname, &ip_number))
2029 return false; 2030 return false;
2030 2031
2031 DCHECK_EQ(key.host_resolver_flags & 2032 DCHECK_EQ(key.host_resolver_flags &
2032 ~(HOST_RESOLVER_CANONNAME | HOST_RESOLVER_LOOPBACK_ONLY | 2033 ~(HOST_RESOLVER_CANONNAME | HOST_RESOLVER_LOOPBACK_ONLY |
2033 HOST_RESOLVER_DEFAULT_FAMILY_SET_DUE_TO_NO_IPV6), 2034 HOST_RESOLVER_DEFAULT_FAMILY_SET_DUE_TO_NO_IPV6),
2034 0) << " Unhandled flag"; 2035 0) << " Unhandled flag";
2035 bool ipv6_disabled = (default_address_family_ == ADDRESS_FAMILY_IPV4) && 2036
2036 !probe_ipv6_support_;
2037 *net_error = OK; 2037 *net_error = OK;
2038 if ((ip_number.size() == kIPv6AddressSize) && ipv6_disabled) { 2038 AddressFamily family = GetAddressFamily(ip_number);
2039 if (family == ADDRESS_FAMILY_IPV6 &&
2040 default_address_family_ == ADDRESS_FAMILY_IPV4 &&
eroman 2014/08/05 22:33:41 As an aside: I am starting to think that "default
mmenke 2014/08/05 22:50:38 I agree that this would be much clearer.
2041 !probe_ipv6_support_) {
eroman 2014/08/05 22:33:41 Can you test for !probe_ipv6_support_ before defau
mmenke 2014/08/05 22:50:38 Done.
2042 // Don't return IPv6 addresses if default address family is set to IPv4,
2043 // and probes are disabled.
2044 *net_error = ERR_NAME_NOT_RESOLVED;
2045 } else if (key.address_family != ADDRESS_FAMILY_UNSPECIFIED &&
2046 key.address_family != family) {
2047 // Don't return IPv6 addresses for IPv4 queries, and vice versa.
2039 *net_error = ERR_NAME_NOT_RESOLVED; 2048 *net_error = ERR_NAME_NOT_RESOLVED;
2040 } else { 2049 } else {
2041 *addresses = AddressList::CreateFromIPAddress(ip_number, info.port()); 2050 *addresses = AddressList::CreateFromIPAddress(ip_number, info.port());
2042 if (key.host_resolver_flags & HOST_RESOLVER_CANONNAME) 2051 if (key.host_resolver_flags & HOST_RESOLVER_CANONNAME)
2043 addresses->SetDefaultCanonicalName(); 2052 addresses->SetDefaultCanonicalName();
2044 } 2053 }
2045 return true; 2054 return true;
2046 } 2055 }
2047 2056
2048 bool HostResolverImpl::ServeFromCache(const Key& key, 2057 bool HostResolverImpl::ServeFromCache(const Key& key,
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
2350 dns_client_->SetConfig(dns_config); 2359 dns_client_->SetConfig(dns_config);
2351 num_dns_failures_ = 0; 2360 num_dns_failures_ = 0;
2352 if (dns_client_->GetConfig()) 2361 if (dns_client_->GetConfig())
2353 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true); 2362 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true);
2354 } 2363 }
2355 2364
2356 AbortDnsTasks(); 2365 AbortDnsTasks();
2357 } 2366 }
2358 2367
2359 } // namespace net 2368 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/dns/host_resolver_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698