mirror of
https://github.com/nodejs/node.git
synced 2026-11-26 21:58:26 -05:00
dns: validate port range in setServers()
Signed-off-by: Renegade334 <contact.9a5d6388@renegade334.me.uk> PR-URL: https://github.com/nodejs/node/pull/65021 Reviewed-By: Aviv Keller <me@aviv.sh> Reviewed-By: Tim Perry <pimterry@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
1 parent
c5588d71ad
commit
00c71fec93
2 files changed
+21
-3
No files matched your search
@@ -24,6 +24,7 @@ const {
|
||||
validateArray,
|
||||
validateInt32,
|
||||
validateOneOf,
|
||||
validatePort,
|
||||
validateString,
|
||||
validateUint32,
|
||||
} = require('internal/validators');
|
||||
@@ -129,6 +130,7 @@ class ResolverBase {
|
||||
if (ipVersion !== 0) {
|
||||
const port = NumberParseInt(
|
||||
RegExpPrototypeSymbolReplace(addrSplitRE, serv, '$2')) || IANA_DNS_PORT;
|
||||
validatePort(port);
|
||||
return ArrayPrototypePush(newSet, [ipVersion, match[1], port]);
|
||||
}
|
||||
}
|
||||
@@ -138,13 +140,13 @@ class ResolverBase {
|
||||
|
||||
if (addrSplitMatch) {
|
||||
const hostIP = addrSplitMatch[1];
|
||||
const port = addrSplitMatch[2] || IANA_DNS_PORT;
|
||||
const port = NumberParseInt(addrSplitMatch[2]) || IANA_DNS_PORT;
|
||||
|
||||
ipVersion = isIP(hostIP);
|
||||
|
||||
if (ipVersion !== 0) {
|
||||
return ArrayPrototypePush(
|
||||
newSet, [ipVersion, hostIP, NumberParseInt(port)]);
|
||||
validatePort(port);
|
||||
return ArrayPrototypePush(newSet, [ipVersion, hostIP, port]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -90,6 +90,22 @@ assert(existing.length > 0);
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
// Out-of-range ports, which should throw a clean error.
|
||||
const invalidPorts = [2 ** 16, 2 ** 32, 2 ** 64];
|
||||
invalidPorts.forEach((port) => {
|
||||
assert.throws(
|
||||
() => {
|
||||
dns.setServers([`1.2.3.4:${port}`]);
|
||||
},
|
||||
{
|
||||
name: 'RangeError',
|
||||
code: 'ERR_SOCKET_BAD_PORT'
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
const goog = [
|
||||
'8.8.8.8',
|
||||
'8.8.4.4',
|
||||
|
||||
Reference in new issue
Block a user