Skip to content

Commit 87d0d7a

Browse files
anonrigTrott
authored andcommitted
url: validate ipv4 part length
PR-URL: #42915 Fixes: #42914 Reviewed-By: Stephen Belanger <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
1 parent 3d0fc13 commit 87d0d7a

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

src/node_url.cc

+4-1
Original file line numberDiff line numberDiff line change
@@ -411,8 +411,11 @@ void URLHost::ParseIPv4Host(const char* input, size_t length, bool* is_ipv4) {
411411
const char ch = pointer < end ? pointer[0] : kEOL;
412412
int64_t remaining = end - pointer - 1;
413413
if (ch == '.' || ch == kEOL) {
414-
if (++parts > static_cast<int>(arraysize(numbers)))
414+
// If parts’s size is greater than 4, validation error, return failure.
415+
if (++parts > static_cast<int>(arraysize(numbers))) {
416+
*is_ipv4 = true;
415417
return;
418+
}
416419
if (pointer == mark)
417420
return;
418421
int64_t n = ParseNumber(mark, pointer);

test/fixtures/wpt/url/resources/urltestdata.json

+6-11
Original file line numberDiff line numberDiff line change
@@ -5317,17 +5317,12 @@
53175317
{
53185318
"input": "http://256.256.256.256.256",
53195319
"base": "http://other.com/",
5320-
"href": "http://256.256.256.256.256/",
5321-
"origin": "http://256.256.256.256.256",
5322-
"protocol": "http:",
5323-
"username": "",
5324-
"password": "",
5325-
"host": "256.256.256.256.256",
5326-
"hostname": "256.256.256.256.256",
5327-
"port": "",
5328-
"pathname": "/",
5329-
"search": "",
5330-
"hash": ""
5320+
"failure": true
5321+
},
5322+
{
5323+
"input": "http://256.256.256.256.256.",
5324+
"base": "http://other.com/",
5325+
"failure": true
53315326
},
53325327
{
53335328
"input": "https://0x.0x.0",

0 commit comments

Comments
 (0)