Skip to content

Commit 9ceed7a

Browse files
aduh95danielleadams
authored andcommitted
dns: fix port validation
Previously the error message generation would throw if the port was of type `"symbol"`. PR-URL: #45135 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
1 parent a534175 commit 9ceed7a

File tree

2 files changed

+2
-7
lines changed

2 files changed

+2
-7
lines changed

lib/internal/errors.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1569,7 +1569,7 @@ E('ERR_SOCKET_BAD_PORT', (name, port, allowZero = true) => {
15691569
assert(typeof allowZero === 'boolean',
15701570
"The 'allowZero' argument must be of type boolean.");
15711571
const operator = allowZero ? '>=' : '>';
1572-
return `${name} should be ${operator} 0 and < 65536. Received ${port}.`;
1572+
return `${name} should be ${operator} 0 and < 65536. Received ${determineSpecificType(port)}.`;
15731573
}, RangeError);
15741574
E('ERR_SOCKET_BAD_TYPE',
15751575
'Bad socket type specified. Valid types are: udp4, udp6', TypeError);

test/parallel/test-dns.js

+1-6
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,6 @@ dns.lookup('', {
310310
const portErr = (port) => {
311311
const err = {
312312
code: 'ERR_SOCKET_BAD_PORT',
313-
message:
314-
`Port should be >= 0 and < 65536. Received ${port}.`,
315313
name: 'RangeError'
316314
};
317315

@@ -323,10 +321,7 @@ const portErr = (port) => {
323321
dns.lookupService('0.0.0.0', port, common.mustNotCall());
324322
}, err);
325323
};
326-
portErr(null);
327-
portErr(undefined);
328-
portErr(65538);
329-
portErr('test');
324+
[null, undefined, 65538, 'test', NaN, Infinity, Symbol(), 0n, true, false, '', () => {}, {}].forEach(portErr);
330325

331326
assert.throws(() => {
332327
dns.lookupService('0.0.0.0', 80, null);

0 commit comments

Comments
 (0)