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: improve setServers() errors and performance · nodejs/node@65b9c42

File tree

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

‎lib/dns.js‎

Copy file name to clipboardExpand all lines: lib/dns.js
+10-5Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ function setServers(servers) {
289289
// servers cares won't have any servers available for resolution
290290
const orig = this._handle.getServers();
291291
const newSet = [];
292-
const IPv6RE = /\[(.*)\]/;
292+
const IPv6RE = /^\[([^[\]]*)\]/;
293293
const addrSplitRE = /(^.+?)(?::(\d+))?$/;
294294

295295
servers.forEach((serv) => {
@@ -309,11 +309,16 @@ function setServers(servers) {
309309
}
310310
}
311311

312-
const [, s, p] = serv.match(addrSplitRE);
313-
ipVersion = isIP(s);
312+
// addr::port
313+
const addrSplitMatch = serv.match(addrSplitRE);
314+
if (addrSplitMatch) {
315+
const hostIP = addrSplitMatch[1];
316+
const port = addrSplitMatch[2] || IANA_DNS_PORT;
314317

315-
if (ipVersion !== 0) {
316-
return newSet.push([ipVersion, s, parseInt(p)]);
318+
ipVersion = isIP(hostIP);
319+
if (ipVersion !== 0) {
320+
return newSet.push([ipVersion, hostIP, parseInt(port)]);
321+
}
317322
}
318323

319324
throw new ERR_INVALID_IP_ADDRESS(serv);
Collapse file

‎test/parallel/test-dns.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-dns.js
+25Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,31 @@ assert(existing.length > 0);
6262
]);
6363
}
6464

65+
{
66+
// Various invalidities, all of which should throw a clean error.
67+
const invalidServers = [
68+
' ',
69+
'\n',
70+
'\0',
71+
'1'.repeat(3 * 4),
72+
// Check for REDOS issues.
73+
':'.repeat(100000),
74+
'['.repeat(100000),
75+
'['.repeat(100000) + ']'.repeat(100000) + 'a'
76+
];
77+
invalidServers.forEach((serv) => {
78+
assert.throws(
79+
() => {
80+
dns.setServers([serv]);
81+
},
82+
{
83+
name: 'TypeError [ERR_INVALID_IP_ADDRESS]',
84+
code: 'ERR_INVALID_IP_ADDRESS'
85+
}
86+
);
87+
});
88+
}
89+
6590
const goog = [
6691
'8.8.8.8',
6792
'8.8.4.4',

0 commit comments

Comments
0 (0)
You are visitor 01402775 — 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.