Chromium Code Reviews| Index: net/base/net_util.cc |
| diff --git a/net/base/net_util.cc b/net/base/net_util.cc |
| index 3b49dffb5c20d889003a09755276ddaa8e41542d..40c33b8c2d37695ce7bf4bbbb3c17a8f3f813ec2 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 = strlen(kLocalhostTLD); |
|
Ryan Sleevi
2015/02/27 03:21:10
DANGER: strlen is a function call, which violates
estark
2015/02/27 05:00:47
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,24 @@ bool IsLocalhost(const std::string& host) { |
| return false; |
| } |
| +bool IsLocalhostTLD(const std::string& host) { |
|
Ryan Sleevi
2015/02/27 03:21:10
You can avoid the double comparison
if (host.empt
estark
2015/02/27 05:00:47
Done.
|
| + size_t host_length = host.length(); |
| + |
| + // First try to match against ".localhost", then against ".localhost." |
| + // with the trailing dot. |
| + |
| + if (host_length < kLocalhostTLDLength - 1) |
| + return false; |
| + if (host.compare(host_length - kLocalhostTLDLength + 1, std::string::npos, |
| + kLocalhostTLD, 0, kLocalhostTLDLength - 1) == 0) |
| + return true; |
| + |
| + 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) { |
| } |