Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 24246a2

Browse filesBrowse files
Lxxyxdanielleadams
authored andcommitted
net: throw ERR_OUT_OF_RANGE if blockList.addSubnet prefix is NaN
Fixes: #36731 PR-URL: #36732 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 2d8423d commit 24246a2
Copy full SHA for 24246a2

File tree

Expand file treeCollapse file tree

2 files changed

+5
-7
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+5
-7
lines changed
Open diff view settings
Collapse file

‎lib/internal/blocklist.js‎

Copy file name to clipboardExpand all lines: lib/internal/blocklist.js
+4-7Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ const { owner_symbol } = internalBinding('symbols');
2222
const {
2323
ERR_INVALID_ARG_TYPE,
2424
ERR_INVALID_ARG_VALUE,
25-
ERR_OUT_OF_RANGE,
2625
} = require('internal/errors').codes;
2726

27+
const { validateInt32 } = require('internal/validators');
28+
2829
class BlockList {
2930
constructor(handle = new BlockListHandle()) {
3031
// The handle argument is an intentionally undocumented
@@ -81,22 +82,18 @@ class BlockList {
8182
addSubnet(network, prefix, family = 'ipv4') {
8283
if (typeof network !== 'string')
8384
throw new ERR_INVALID_ARG_TYPE('network', 'string', network);
84-
if (typeof prefix !== 'number')
85-
throw new ERR_INVALID_ARG_TYPE('prefix', 'number', prefix);
8685
if (typeof family !== 'string')
8786
throw new ERR_INVALID_ARG_TYPE('family', 'string', family);
8887
family = family.toLowerCase();
8988
let type;
9089
switch (family) {
9190
case 'ipv4':
9291
type = AF_INET;
93-
if (prefix < 0 || prefix > 32)
94-
throw new ERR_OUT_OF_RANGE(prefix, '>= 0 and <= 32', prefix);
92+
validateInt32(prefix, 'prefix', 0, 32);
9593
break;
9694
case 'ipv6':
9795
type = AF_INET6;
98-
if (prefix < 0 || prefix > 128)
99-
throw new ERR_OUT_OF_RANGE(prefix, '>= 0 and <= 128', prefix);
96+
validateInt32(prefix, 'prefix', 0, 128);
10097
break;
10198
default:
10299
throw new ERR_INVALID_ARG_VALUE('family', family);
Collapse file

‎test/parallel/test-blocklist.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-blocklist.js
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ const util = require('util');
150150
const blockList = new BlockList();
151151
assert.throws(() => blockList.addSubnet(1), /ERR_INVALID_ARG_TYPE/);
152152
assert.throws(() => blockList.addSubnet('', ''), /ERR_INVALID_ARG_TYPE/);
153+
assert.throws(() => blockList.addSubnet('', NaN), /ERR_OUT_OF_RANGE/);
153154
assert.throws(() => blockList.addSubnet('', 1, 1), /ERR_INVALID_ARG_TYPE/);
154155
assert.throws(() => blockList.addSubnet('', 1, ''), /ERR_INVALID_ARG_VALUE/);
155156

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.