url: validate ipv4 part length

PR-URL: https://github.com/nodejs/node/pull/42915
Fixes: https://github.com/nodejs/node/issues/42914
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This commit is contained in:
Yagiz Nizipli
2022-04-29 12:54:38 -04:00
committed by Rich Trott
parent 3d0fc13ba3
commit 87d0d7a069
2 changed files with 10 additions and 12 deletions

View File

@@ -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 partss 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);

View File

@@ -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",