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

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: add 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..a16d9e7116bd45f70d19bcf114b803e870de63a3 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 int kLocalhostTLDLength = strlen(kLocalhostTLD);
+
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,14 @@ bool IsLocalhost(const std::string& host) {
return false;
}
+bool IsLocalhostTLD(const std::string& host) {
Ryan Sleevi 2015/02/19 22:24:56 I guess it depends on the rules for |host| here, b
estark 2015/02/20 01:55:19 Gotcha. Done in this function, and filed another b
+ int host_length = host.length();
Ryan Sleevi 2015/02/19 22:24:56 s/int/size_t/ - right numeric for the job
estark 2015/02/20 01:55:19 Done.
+ if (host_length < kLocalhostTLDLength)
+ return false;
+ return host.compare(host_length - kLocalhostTLDLength, std::string::npos,
+ kLocalhostTLD) == 0;
+}
+
NetworkInterface::NetworkInterface()
: type(NetworkChangeNotifier::CONNECTION_UNKNOWN), prefix_length(0) {
}

Powered by Google App Engine
This is Rietveld 408576698