summaryrefslogtreecommitdiffstats
path: root/net/base/net_util.cc
diff options
context:
space:
mode:
authoreroman <eroman@chromium.org>2014-09-24 16:42:00 -0700
committerCommit bot <commit-bot@chromium.org>2014-09-24 23:46:26 +0000
commitff374b7fd49f6ddf9f4ee597759d65996534379a (patch)
tree146e83d7ac50d4698cbd9a463f43f90a81bbf943 /net/base/net_util.cc
parent94f2309233e6d1af2c8c85e223c88d76626ccdd5 (diff)
downloadchromium_src-ff374b7fd49f6ddf9f4ee597759d65996534379a.zip
chromium_src-ff374b7fd49f6ddf9f4ee597759d65996534379a.tar.gz
chromium_src-ff374b7fd49f6ddf9f4ee597759d65996534379a.tar.bz2
Change ParseHostAndPort() to not include brackets around IPv6 literals.
There were several consumers assuming that the returned hosts had no brackets. BUG=417417 Review URL: https://codereview.chromium.org/602973002 Cr-Commit-Position: refs/heads/master@{#296569}
Diffstat (limited to 'net/base/net_util.cc')
-rw-r--r--net/base/net_util.cc17
1 files changed, 17 insertions, 0 deletions
diff --git a/net/base/net_util.cc b/net/base/net_util.cc
index 704add2..d63dfe8 100644
--- a/net/base/net_util.cc
+++ b/net/base/net_util.cc
@@ -376,6 +376,23 @@ bool ParseHostAndPort(std::string::const_iterator host_and_port_begin,
if (port_component.len == 0)
return false; // Reject inputs like "foo:"
+ unsigned char tmp_ipv6_addr[16];
+
+ // If the hostname starts with a bracket, it is either an IPv6 literal or
+ // invalid. If it is an IPv6 literal then strip the brackets.
+ if (hostname_component.len > 0 &&
+ auth_begin[hostname_component.begin] == '[') {
+ if (auth_begin[hostname_component.end() - 1] == ']' &&
+ url::IPv6AddressToNumber(
+ auth_begin, hostname_component, tmp_ipv6_addr)) {
+ // Strip the brackets.
+ hostname_component.begin++;
+ hostname_component.len -= 2;
+ } else {
+ return false;
+ }
+ }
+
// Pass results back to caller.
host->assign(auth_begin + hostname_component.begin, hostname_component.len);
*port = parsed_port_number;