GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — dns: validate port range in `setServers()` · nodejs/node@15f95fc

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/internal/dns
    • utils.js
  • test/parallel
    • test-dns.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/dns/utils.js‎

Copy file name to clipboardExpand all lines: lib/internal/dns/utils.js
+5-3Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const {
2424
validateArray,
2525
validateInt32,
2626
validateOneOf,
27+
validatePort,
2728
validateString,
2829
validateUint32,
2930
} = require('internal/validators');
@@ -129,6 +130,7 @@ class ResolverBase {
129130
if (ipVersion !== 0) {
130131
const port = NumberParseInt(
131132
RegExpPrototypeSymbolReplace(addrSplitRE, serv, '$2')) || IANA_DNS_PORT;
133+
validatePort(port);
132134
return ArrayPrototypePush(newSet, [ipVersion, match[1], port]);
133135
}
134136
}
@@ -138,13 +140,13 @@ class ResolverBase {
138140

139141
if (addrSplitMatch) {
140142
const hostIP = addrSplitMatch[1];
141-
const port = addrSplitMatch[2] || IANA_DNS_PORT;
143+
const port = NumberParseInt(addrSplitMatch[2]) || IANA_DNS_PORT;
142144

143145
ipVersion = isIP(hostIP);
144146

145147
if (ipVersion !== 0) {
146-
return ArrayPrototypePush(
147-
newSet, [ipVersion, hostIP, NumberParseInt(port)]);
148+
validatePort(port);
149+
return ArrayPrototypePush(newSet, [ipVersion, hostIP, port]);
148150
}
149151
}
150152

Collapse file

‎test/parallel/test-dns.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-dns.js
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,22 @@ assert(existing.length > 0);
9090
});
9191
}
9292

93+
{
94+
// Out-of-range ports, which should throw a clean error.
95+
const invalidPorts = [2 ** 16, 2 ** 32, 2 ** 64];
96+
invalidPorts.forEach((port) => {
97+
assert.throws(
98+
() => {
99+
dns.setServers([`1.2.3.4:${port}`]);
100+
},
101+
{
102+
name: 'RangeError',
103+
code: 'ERR_SOCKET_BAD_PORT'
104+
}
105+
);
106+
});
107+
}
108+
93109
const goog = [
94110
'8.8.8.8',
95111
'8.8.4.4',

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.