Skip to content

Commit 4e446a9

Browse files
committed
url: should validate ipv4 part length
1 parent 27ecf1d commit 4e446a9

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/node_url.cc

Lines changed: 4 additions & 1 deletion
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);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
'use strict';
2+
3+
require('../common');
4+
5+
const assert = require('assert');
6+
7+
assert.throws(() => new URL('https://256.256.256.256'), { code: 'ERR_INVALID_URL' });
8+
assert.throws(() => new URL('https://256.256.256.256.256'), { code: 'ERR_INVALID_URL' });

0 commit comments

Comments
 (0)