-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
process: add range validation to debugPort
This commit adds validation to the process.debugPort setter. Fixes: #38037 PR-URL: #38205 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com>
- Loading branch information
Showing
2 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
|
||
common.skipIfInspectorDisabled(); | ||
common.skipIfWorker(); | ||
|
||
const assert = require('assert'); | ||
const kMinPort = 1024; | ||
const kMaxPort = 65535; | ||
|
||
function check(value, expected) { | ||
process.debugPort = value; | ||
assert.strictEqual(process.debugPort, expected); | ||
} | ||
|
||
// Expected usage with numbers. | ||
check(0, 0); | ||
check(kMinPort, kMinPort); | ||
check(kMinPort + 1, kMinPort + 1); | ||
check(kMaxPort - 1, kMaxPort - 1); | ||
check(kMaxPort, kMaxPort); | ||
|
||
// Numeric strings coerce. | ||
check('0', 0); | ||
check(`${kMinPort}`, kMinPort); | ||
check(`${kMinPort + 1}`, kMinPort + 1); | ||
check(`${kMaxPort - 1}`, kMaxPort - 1); | ||
check(`${kMaxPort}`, kMaxPort); | ||
|
||
// Most other values are coerced to 0. | ||
check('', 0); | ||
check(false, 0); | ||
check(NaN, 0); | ||
check(Infinity, 0); | ||
check(-Infinity, 0); | ||
check(function() {}, 0); | ||
check({}, 0); | ||
check([], 0); | ||
|
||
// Symbols do not coerce. | ||
assert.throws(() => { | ||
process.debugPort = Symbol(); | ||
}, /^TypeError: Cannot convert a Symbol value to a number$/); | ||
|
||
// Verify port bounds checking. | ||
[ | ||
true, | ||
-1, | ||
1, | ||
kMinPort - 1, | ||
kMaxPort + 1, | ||
'-1', | ||
'1', | ||
`${kMinPort - 1}`, | ||
`${kMaxPort + 1}`, | ||
].forEach((value) => { | ||
assert.throws(() => { | ||
process.debugPort = value; | ||
}, /^RangeError: process\.debugPort must be 0 or in range 1024 to 65535$/); | ||
}); |