File tree Expand file tree Collapse file tree 3 files changed +26
-6
lines changed Expand file tree Collapse file tree 3 files changed +26
-6
lines changed Original file line number Diff line number Diff line change @@ -1597,10 +1597,11 @@ void URL::Parse(const char* input,
1597
1597
ch == ' #' ||
1598
1598
special_back_slash) {
1599
1599
if (buffer.size () > 0 ) {
1600
- int port = 0 ;
1601
- for (size_t i = 0 ; i < buffer.size (); i++)
1600
+ unsigned port = 0 ;
1601
+ // the condition port <= 0xffff prevents integer overflow
1602
+ for (size_t i = 0 ; port <= 0xffff && i < buffer.size (); i++)
1602
1603
port = port * 10 + buffer[i] - ' 0' ;
1603
- if (port < 0 || port > 0xffff ) {
1604
+ if (port > 0xffff ) {
1604
1605
// TODO(TimothyGu): This hack is currently needed for the host
1605
1606
// setter since it needs access to hostname if it is valid, and
1606
1607
// if the FAILED flag is set the entire response to JS layer
@@ -1611,7 +1612,8 @@ void URL::Parse(const char* input,
1611
1612
url->flags |= URL_FLAGS_FAILED;
1612
1613
return ;
1613
1614
}
1614
- url->port = NormalizePort (url->scheme , port);
1615
+ // the port is valid
1616
+ url->port = NormalizePort (url->scheme , static_cast <int >(port));
1615
1617
buffer.clear ();
1616
1618
} else if (has_state_override) {
1617
1619
// TODO(TimothyGu): Similar case as above.
Original file line number Diff line number Diff line change 2
2
3
3
/* The following tests are copied from WPT. Modifications to them should be
4
4
upstreamed first. Refs:
5
- https://github.com/w3c/web-platform-tests/blob/5d149f0 /url/urltestdata.json
5
+ https://github.com/w3c/web-platform-tests/blob/11757f1 /url/urltestdata.json
6
6
License: http://www.w3.org/Consortium/Legal/2008/04-testsuite-copyright.html
7
7
*/
8
8
module . exports =
@@ -5811,6 +5811,24 @@ module.exports =
5811
5811
"base" : "about:blank" ,
5812
5812
"failure" : true
5813
5813
} ,
5814
+ "Port overflow (2^32 + 81)" ,
5815
+ {
5816
+ "input" : "http://f:4294967377/c" ,
5817
+ "base" : "http://example.org/" ,
5818
+ "failure" : true
5819
+ } ,
5820
+ "Port overflow (2^64 + 81)" ,
5821
+ {
5822
+ "input" : "http://f:18446744073709551697/c" ,
5823
+ "base" : "http://example.org/" ,
5824
+ "failure" : true
5825
+ } ,
5826
+ "Port overflow (2^128 + 81)" ,
5827
+ {
5828
+ "input" : "http://f:340282366920938463463374607431768211537/c" ,
5829
+ "base" : "http://example.org/" ,
5830
+ "failure" : true
5831
+ } ,
5814
5832
"# Non-special-URL path tests" ,
5815
5833
{
5816
5834
"input" : "sc://ñ" ,
Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ const failureTests = tests.filter((test) => test.failure).concat([
26
26
] ) ;
27
27
28
28
const expectedError = common . expectsError (
29
- { code : 'ERR_INVALID_URL' , type : TypeError } , 110 ) ;
29
+ { code : 'ERR_INVALID_URL' , type : TypeError } , failureTests . length ) ;
30
30
31
31
for ( const test of failureTests ) {
32
32
assert . throws (
You can’t perform that action at this time.
0 commit comments