Skip to content

Commit 24246a2

Browse 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 <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 2d8423d commit 24246a2

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

‎lib/internal/blocklist.js‎

Lines 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
classBlockList{
2930
constructor(handle=newBlockListHandle()){
3031
// The handle argument is an intentionally undocumented
@@ -81,22 +82,18 @@ class BlockList{
8182
addSubnet(network,prefix,family='ipv4'){
8283
if(typeofnetwork!=='string')
8384
thrownewERR_INVALID_ARG_TYPE('network','string',network);
84-
if(typeofprefix!=='number')
85-
thrownewERR_INVALID_ARG_TYPE('prefix','number',prefix);
8685
if(typeoffamily!=='string')
8786
thrownewERR_INVALID_ARG_TYPE('family','string',family);
8887
family=family.toLowerCase();
8988
lettype;
9089
switch(family){
9190
case'ipv4':
9291
type=AF_INET;
93-
if(prefix<0||prefix>32)
94-
thrownewERR_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-
thrownewERR_OUT_OF_RANGE(prefix,'>= 0 and <= 128',prefix);
96+
validateInt32(prefix,'prefix',0,128);
10097
break;
10198
default:
10299
thrownewERR_INVALID_ARG_VALUE('family',family);

‎test/parallel/test-blocklist.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ const util = require('util');
150150
constblockList=newBlockList();
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)