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 address type in lookupService · nodejs/node@02560d4

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib
    • dns.js
    • internal/dns
      • promises.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
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ const {
8484
validateNumber,
8585
validateOneOf,
8686
validatePort,
87+
validateString,
8788
validateStringWithoutNullBytes,
8889
} = require('internal/validators');
8990

@@ -275,6 +276,8 @@ function lookupService(address, port, callback) {
275276
if (arguments.length !== 3)
276277
throw new ERR_MISSING_ARGS('address', 'port', 'callback');
277278

279+
validateString(address, 'address');
280+
278281
if (isIP(address) === 0)
279282
throw new ERR_INVALID_ARG_VALUE('address', address);
280283

Collapse file

‎lib/internal/dns/promises.js‎

Copy file name to clipboardExpand all lines: lib/internal/dns/promises.js
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,8 @@ function lookupService(address, port) {
283283
if (arguments.length !== 2)
284284
throw new ERR_MISSING_ARGS('address', 'port');
285285

286+
validateString(address, 'address');
287+
286288
if (isIP(address) === 0)
287289
throw new ERR_INVALID_ARG_VALUE('address', address);
288290

Collapse file

‎test/parallel/test-dns.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-dns.js
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,24 @@ dns.lookup('', {
344344
}, err);
345345
}
346346

347+
{
348+
const invalidAddress = Buffer.from('127.0.0.1');
349+
const err = {
350+
code: 'ERR_INVALID_ARG_TYPE',
351+
name: 'TypeError',
352+
message: 'The "address" argument must be of type string. ' +
353+
'Received an instance of Buffer'
354+
};
355+
356+
assert.throws(() => {
357+
dnsPromises.lookupService(invalidAddress, 0);
358+
}, err);
359+
360+
assert.throws(() => {
361+
dns.lookupService(invalidAddress, 0, common.mustNotCall());
362+
}, err);
363+
}
364+
347365
[null, undefined, 65538, 'test', NaN, Infinity, Symbol(), 0n, true, false, '', () => {}, {}].forEach((port) => {
348366
const err = {
349367
code: 'ERR_SOCKET_BAD_PORT',

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.