Skip to content

Commit

Permalink
url: validate ipv4 part length
Browse files Browse the repository at this point in the history
PR-URL: #42915
Fixes: #42914
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
  • Loading branch information
anonrig authored and Trott committed May 1, 2022
1 parent 3d0fc13 commit 87d0d7a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
5 changes: 4 additions & 1 deletion src/node_url.cc
Expand Up @@ -411,8 +411,11 @@ void URLHost::ParseIPv4Host(const char* input, size_t length, bool* is_ipv4) {
const char ch = pointer < end ? pointer[0] : kEOL;
int64_t remaining = end - pointer - 1;
if (ch == '.' || ch == kEOL) {
if (++parts > static_cast<int>(arraysize(numbers)))
// If parts’s size is greater than 4, validation error, return failure.
if (++parts > static_cast<int>(arraysize(numbers))) {
*is_ipv4 = true;
return;
}
if (pointer == mark)
return;
int64_t n = ParseNumber(mark, pointer);
Expand Down
17 changes: 6 additions & 11 deletions test/fixtures/wpt/url/resources/urltestdata.json
Expand Up @@ -5317,17 +5317,12 @@
{
"input": "http://256.256.256.256.256",
"base": "http://other.com/",
"href": "http://256.256.256.256.256/",
"origin": "http://256.256.256.256.256",
"protocol": "http:",
"username": "",
"password": "",
"host": "256.256.256.256.256",
"hostname": "256.256.256.256.256",
"port": "",
"pathname": "/",
"search": "",
"hash": ""
"failure": true
},
{
"input": "http://256.256.256.256.256.",
"base": "http://other.com/",
"failure": true
},
{
"input": "https://0x.0x.0",
Expand Down

0 comments on commit 87d0d7a

Please sign in to comment.