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

Unified Diff: net/base/net_util.cc

Issue 602973002: Change ParseHostAndPort() to not include brackets around IPv6 literals. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add a comment Created 6 years, 3 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 704add2e8315b6c31658bc75a4edea50a556e2f2..d63dfe80bc4d844cb454296339e7d8404c054e32 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;
« 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