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@152a326

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
@@ -83,6 +83,7 @@ const {
8383
validateNumber,
8484
validateOneOf,
8585
validatePort,
86+
validateString,
8687
validateStringWithoutNullBytes,
8788
} = require('internal/validators');
8889

@@ -269,6 +270,8 @@ function lookupService(address, port, callback) {
269270
if (arguments.length !== 3)
270271
throw new ERR_MISSING_ARGS('address', 'port', 'callback');
271272

273+
validateString(address, 'address');
274+
272275
if (isIP(address) === 0)
273276
throw new ERR_INVALID_ARG_VALUE('address', address);
274277

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
@@ -282,6 +282,8 @@ function lookupService(address, port) {
282282
if (arguments.length !== 2)
283283
throw new ERR_MISSING_ARGS('address', 'port');
284284

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

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
@@ -394,6 +394,24 @@ assert.throws(() => {
394394
}, err);
395395
}
396396

397+
{
398+
const invalidAddress = Buffer.from('127.0.0.1');
399+
const err = {
400+
code: 'ERR_INVALID_ARG_TYPE',
401+
name: 'TypeError',
402+
message: 'The "address" argument must be of type string. ' +
403+
'Received an instance of Buffer'
404+
};
405+
406+
assert.throws(() => {
407+
dnsPromises.lookupService(invalidAddress, 0);
408+
}, err);
409+
410+
assert.throws(() => {
411+
dns.lookupService(invalidAddress, 0, common.mustNotCall());
412+
}, err);
413+
}
414+
397415
[null, undefined, 65538, 'test', NaN, Infinity, Symbol(), 0n, true, false, '', () => {}, {}].forEach((port) => {
398416
const err = {
399417
code: 'ERR_SOCKET_BAD_PORT',

0 commit comments

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