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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/base/net_util.h" 5 #include "net/base/net_util.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <string.h> 8 #include <string.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 369
370 // If parsing failed, port_number will be either PORT_INVALID or 370 // If parsing failed, port_number will be either PORT_INVALID or
371 // PORT_UNSPECIFIED, both of which are negative. 371 // PORT_UNSPECIFIED, both of which are negative.
372 if (parsed_port_number < 0) 372 if (parsed_port_number < 0)
373 return false; // Failed parsing the port number. 373 return false; // Failed parsing the port number.
374 } 374 }
375 375
376 if (port_component.len == 0) 376 if (port_component.len == 0)
377 return false; // Reject inputs like "foo:" 377 return false; // Reject inputs like "foo:"
378 378
379 unsigned char tmp_ipv6_addr[16];
380
381 // If the hostname starts with a bracket, it is either an IPv6 literal or
382 // invalid. If it is an IPv6 literal then strip the brackets.
383 if (hostname_component.len > 0 &&
384 auth_begin[hostname_component.begin] == '[') {
385 if (auth_begin[hostname_component.end() - 1] == ']' &&
386 url::IPv6AddressToNumber(
387 auth_begin, hostname_component, tmp_ipv6_addr)) {
388 // Strip the brackets.
389 hostname_component.begin++;
390 hostname_component.len -= 2;
391 } else {
392 return false;
393 }
394 }
395
379 // Pass results back to caller. 396 // Pass results back to caller.
380 host->assign(auth_begin + hostname_component.begin, hostname_component.len); 397 host->assign(auth_begin + hostname_component.begin, hostname_component.len);
381 *port = parsed_port_number; 398 *port = parsed_port_number;
382 399
383 return true; // Success. 400 return true; // Success.
384 } 401 }
385 402
386 bool ParseHostAndPort(const std::string& host_and_port, 403 bool ParseHostAndPort(const std::string& host_and_port,
387 std::string* host, 404 std::string* host,
388 int* port) { 405 int* port) {
(...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after
1037 1054
1038 unsigned MaskPrefixLength(const IPAddressNumber& mask) { 1055 unsigned MaskPrefixLength(const IPAddressNumber& mask) {
1039 IPAddressNumber all_ones(mask.size(), 0xFF); 1056 IPAddressNumber all_ones(mask.size(), 0xFF);
1040 return CommonPrefixLength(mask, all_ones); 1057 return CommonPrefixLength(mask, all_ones);
1041 } 1058 }
1042 1059
1043 ScopedWifiOptions::~ScopedWifiOptions() { 1060 ScopedWifiOptions::~ScopedWifiOptions() {
1044 } 1061 }
1045 1062
1046 } // namespace net 1063 } // namespace net
OLDNEW
« 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