Skip to content

Commit

Permalink
url: should validate ipv4 part length
Browse files Browse the repository at this point in the history
  • Loading branch information
anonrig committed Apr 29, 2022
1 parent 27ecf1d commit 4e446a9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/node_url.cc
Original file line number Diff line number Diff line change
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
8 changes: 8 additions & 0 deletions test/parallel/test-whatwg-url-ipv4.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict';

require('../common');

const assert = require('assert');

assert.throws(() => new URL('https://256.256.256.256'), { code: 'ERR_INVALID_URL' });
assert.throws(() => new URL('https://256.256.256.256.256'), { code: 'ERR_INVALID_URL' });

0 comments on commit 4e446a9

Please sign in to comment.