Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: url parser should throw error on invalid ipv4 #42915

Merged
merged 1 commit into from May 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will introduce more failing tests. I've opened an additional issue in order to keep track of spec compliance and fix those issues.

},
{
"input": "https://0x.0x.0",
Expand Down