镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/internal/dns/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const {
validateArray,
validateInt32,
validateOneOf,
validatePort,
validateString,
validateUint32,
} = require('internal/validators');
Expand Down Expand Up @@ -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]);
}
}
Expand All @@ -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]);
}
}

Expand Down
16 changes: 16 additions & 0 deletions test/parallel/test-dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Loading