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

Unified Diff: net/base/net_util.cc

Issue 938093003: Always treat .localhost as loopback (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: move constants, add a test case, style fix Created 5 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/base/net_util.h ('k') | net/base/net_util_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/net_util.cc
diff --git a/net/base/net_util.cc b/net/base/net_util.cc
index 3b49dffb5c20d889003a09755276ddaa8e41542d..c893e6164d0301196d9dcff4709bd977baa4a130 100644
--- a/net/base/net_util.cc
+++ b/net/base/net_util.cc
@@ -981,10 +981,9 @@ int GetPortFromSockaddr(const struct sockaddr* address, socklen_t address_len) {
}
bool IsLocalhost(const std::string& host) {
- if (host == "localhost" ||
- host == "localhost.localdomain" ||
- host == "localhost6" ||
- host == "localhost6.localdomain6")
+ if (host == "localhost" || host == "localhost.localdomain" ||
+ host == "localhost6" || host == "localhost6.localdomain6" ||
+ IsLocalhostTLD(host))
return true;
IPAddressNumber ip_number;
@@ -1014,6 +1013,24 @@ bool IsLocalhost(const std::string& host) {
return false;
}
+bool IsLocalhostTLD(const std::string& host) {
+ const char kLocalhostTLD[] = ".localhost";
+ const size_t kLocalhostTLDLength = arraysize(kLocalhostTLD) - 1;
+
+ if (host.empty())
+ return false;
+
+ size_t host_len = host.size();
+ if (*host.rbegin() == '.')
Deprecated (see juliatuttle) 2015/03/26 17:04:36 Nit: host.back()? I think we're using C++11 now, s
Ryan Sleevi 2015/03/26 17:10:56 language, not library, so rbegin is needed
+ --host_len;
+ if (host_len < kLocalhostTLDLength)
+ return false;
+
+ const char* host_suffix = host.data() + host_len - kLocalhostTLDLength;
+ return base::strncasecmp(host_suffix, kLocalhostTLD, kLocalhostTLDLength) ==
+ 0;
+}
+
NetworkInterface::NetworkInterface()
: type(NetworkChangeNotifier::CONNECTION_UNKNOWN), prefix_length(0) {
}
« no previous file with comments | « net/base/net_util.h ('k') | net/base/net_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698