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

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: rsleevi's comments Created 5 years, 10 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
Index: net/base/net_util.cc
diff --git a/net/base/net_util.cc b/net/base/net_util.cc
index 3b49dffb5c20d889003a09755276ddaa8e41542d..35ac9887c7e1293bd9668deff86009b8e3bb3236 100644
--- a/net/base/net_util.cc
+++ b/net/base/net_util.cc
@@ -144,6 +144,9 @@ static const int kAllowedFtpPorts[] = {
22, // ssh
};
+static const char kLocalhostTLD[] = ".localhost";
+static const size_t kLocalhostTLDLength = arraysize(kLocalhostTLD) - 1;
Ryan Sleevi 2015/03/24 23:15:20 Turns out you could move these to line 1024, since
estark 2015/03/25 23:53:33 Done.
+
bool IPNumberPrefixCheck(const IPAddressNumber& ip_number,
const unsigned char* ip_prefix,
size_t prefix_length_in_bits) {
@@ -984,7 +987,8 @@ bool IsLocalhost(const std::string& host) {
if (host == "localhost" ||
host == "localhost.localdomain" ||
host == "localhost6" ||
- host == "localhost6.localdomain6")
+ host == "localhost6.localdomain6" ||
+ IsLocalhostTLD(host))
return true;
IPAddressNumber ip_number;
@@ -1014,6 +1018,21 @@ bool IsLocalhost(const std::string& host) {
return false;
}
+bool IsLocalhostTLD(const std::string& host) {
+ if (host.empty())
+ return false;
+
+ size_t host_len = host.size();
+ if (*host.rbegin() == '.')
+ --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) {
}

Powered by Google App Engine
This is Rietveld 408576698