net: throw ERR_OUT_OF_RANGE if blockList.addSubnet prefix is NaN
Fixes: https://github.com/nodejs/node/issues/36731 PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
parent
6498e054a1
commit
9574e5b632
@ -22,9 +22,10 @@ const { owner_symbol } = internalBinding('symbols');
|
||||
const {
|
||||
ERR_INVALID_ARG_TYPE,
|
||||
ERR_INVALID_ARG_VALUE,
|
||||
ERR_OUT_OF_RANGE,
|
||||
} = require('internal/errors').codes;
|
||||
|
||||
const { validateInt32 } = require('internal/validators');
|
||||
|
||||
class BlockList {
|
||||
constructor(handle = new BlockListHandle()) {
|
||||
// The handle argument is an intentionally undocumented
|
||||
@ -81,8 +82,6 @@ class BlockList {
|
||||
addSubnet(network, prefix, family = 'ipv4') {
|
||||
if (typeof network !== 'string')
|
||||
throw new ERR_INVALID_ARG_TYPE('network', 'string', network);
|
||||
if (typeof prefix !== 'number')
|
||||
throw new ERR_INVALID_ARG_TYPE('prefix', 'number', prefix);
|
||||
if (typeof family !== 'string')
|
||||
throw new ERR_INVALID_ARG_TYPE('family', 'string', family);
|
||||
family = family.toLowerCase();
|
||||
@ -90,13 +89,11 @@ class BlockList {
|
||||
switch (family) {
|
||||
case 'ipv4':
|
||||
type = AF_INET;
|
||||
if (prefix < 0 || prefix > 32)
|
||||
throw new ERR_OUT_OF_RANGE(prefix, '>= 0 and <= 32', prefix);
|
||||
validateInt32(prefix, 'prefix', 0, 32);
|
||||
break;
|
||||
case 'ipv6':
|
||||
type = AF_INET6;
|
||||
if (prefix < 0 || prefix > 128)
|
||||
throw new ERR_OUT_OF_RANGE(prefix, '>= 0 and <= 128', prefix);
|
||||
validateInt32(prefix, 'prefix', 0, 128);
|
||||
break;
|
||||
default:
|
||||
throw new ERR_INVALID_ARG_VALUE('family', family);
|
||||
|
@ -150,6 +150,7 @@ const util = require('util');
|
||||
const blockList = new BlockList();
|
||||
assert.throws(() => blockList.addSubnet(1), /ERR_INVALID_ARG_TYPE/);
|
||||
assert.throws(() => blockList.addSubnet('', ''), /ERR_INVALID_ARG_TYPE/);
|
||||
assert.throws(() => blockList.addSubnet('', NaN), /ERR_OUT_OF_RANGE/);
|
||||
assert.throws(() => blockList.addSubnet('', 1, 1), /ERR_INVALID_ARG_TYPE/);
|
||||
assert.throws(() => blockList.addSubnet('', 1, ''), /ERR_INVALID_ARG_VALUE/);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user