summaryrefslogtreecommitdiffstats
path: root/net/base/host_resolver_impl.cc
diff options
context:
space:
mode:
authoragayev@chromium.org <agayev@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-28 21:34:47 +0000
committeragayev@chromium.org <agayev@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-28 21:34:47 +0000
commit6e78dfb46a07e5ee38225e0cd32fa8b70ed41558 (patch)
treec00c45283a8b8f86eb079395ee4ba56c9954c215 /net/base/host_resolver_impl.cc
parenta13cc36d904c699cd37f80a1c5200f21a7a54671 (diff)
downloadchromium_src-6e78dfb46a07e5ee38225e0cd32fa8b70ed41558.zip
chromium_src-6e78dfb46a07e5ee38225e0cd32fa8b70ed41558.tar.gz
chromium_src-6e78dfb46a07e5ee38225e0cd32fa8b70ed41558.tar.bz2
HostResolverImpl: don't interpret NULL callback argument as a request to do synchronous resolution.
BUG=90547,60149 TEST=net_unittests Review URL: http://codereview.chromium.org/7520026 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@94552 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base/host_resolver_impl.cc')
-rw-r--r--net/base/host_resolver_impl.cc49
1 files changed, 25 insertions, 24 deletions
diff --git a/net/base/host_resolver_impl.cc b/net/base/host_resolver_impl.cc
index af7d0d3..b317ca0 100644
--- a/net/base/host_resolver_impl.cc
+++ b/net/base/host_resolver_impl.cc
@@ -44,6 +44,10 @@ namespace net {
namespace {
+// Limit the size of hostnames that will be resolved to combat issues in
+// some platform's resolvers.
+const size_t kMaxHostLength = 4096;
+
// Helper to mutate the linked list contained by AddressList to the given
// port. Note that in general this is dangerous since the AddressList's
// data might be shared (and you should use AddressList::SetPort).
@@ -1143,6 +1147,19 @@ int HostResolverImpl::Resolve(const RequestInfo& info,
// Update the net log and notify registered observers.
OnStartRequest(source_net_log, request_net_log, request_id, info);
+ // The result of |getaddrinfo| for empty hosts is inconsistent across systems.
+ // On Windows it gives the default interface's address, whereas on Linux it
+ // gives an error. We will make it fail on all platforms for consistency.
+ if (info.hostname().empty() || info.hostname().size() > kMaxHostLength) {
+ OnFinishRequest(source_net_log,
+ request_net_log,
+ request_id,
+ info,
+ ERR_NAME_NOT_RESOLVED,
+ 0);
+ return ERR_NAME_NOT_RESOLVED;
+ }
+
// Build a key that identifies the request in the cache and in the
// outstanding jobs map.
Key key = GetEffectiveKeyForRequest(info);
@@ -1170,6 +1187,13 @@ int HostResolverImpl::Resolve(const RequestInfo& info,
return net_error;
}
+ // Sanity check -- it shouldn't be the case that allow_cached_response is
+ // false while only_use_cached_response is true.
+ DCHECK(info.allow_cached_response() || !info.only_use_cached_response());
+
+ // If callback is NULL, we must be doing cache-only lookup.
+ DCHECK(callback || info.only_use_cached_response());
+
// If we have an unexpired cache entry, use it.
if (info.allow_cached_response() && cache_.get()) {
const HostCache::Entry* cache_entry = cache_->Lookup(
@@ -1201,30 +1225,7 @@ int HostResolverImpl::Resolve(const RequestInfo& info,
return ERR_NAME_NOT_RESOLVED;
}
- // If no callback was specified, do a synchronous resolution.
- if (!callback) {
- AddressList addrlist;
- int os_error = 0;
- int error = ResolveAddrInfo(
- effective_resolver_proc(), key.hostname, key.address_family,
- key.host_resolver_flags, &addrlist, &os_error);
- if (error == OK) {
- MutableSetPort(info.port(), &addrlist);
- *addresses = addrlist;
- }
-
- // Write to cache.
- if (cache_.get())
- cache_->Set(key, error, addrlist, base::TimeTicks::Now());
-
- // Update the net log and notify registered observers.
- OnFinishRequest(source_net_log, request_net_log, request_id, info, error,
- os_error);
-
- return error;
- }
-
- // Create a handle for this request, and pass it back to the user if they
+ // Create a handle for this request, and pass it back to the user if they
// asked for it (out_req != NULL).
Request* req = new Request(source_net_log, request_net_log, request_id, info,
callback, addresses);