GeezerVison is showing github.com — dns: validate address type in lookupService · nodejs/node@02560d4
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/dns.js +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -84,6 +84,7 @@ const { | 84 | 84 | validateNumber, | 85 | 85 | validateOneOf, | 86 | 86 | validatePort, | | 87 | + validateString, | 87 | 88 | validateStringWithoutNullBytes, | 88 | 89 | } = require('internal/validators'); | 89 | 90 |
| @@ -275,6 +276,8 @@ function lookupService(address, port, callback) { | 275 | 276 | if (arguments.length !== 3) | 276 | 277 | throw new ERR_MISSING_ARGS('address', 'port', 'callback'); | 277 | 278 |
| | 279 | + validateString(address, 'address'); | | 280 | + | 278 | 281 | if (isIP(address) === 0) | 279 | 282 | throw new ERR_INVALID_ARG_VALUE('address', address); | 280 | 283 |
| |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/dns/promises.js +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -283,6 +283,8 @@ function lookupService(address, port) { | 283 | 283 | if (arguments.length !== 2) | 284 | 284 | throw new ERR_MISSING_ARGS('address', 'port'); | 285 | 285 |
| | 286 | + validateString(address, 'address'); | | 287 | + | 286 | 288 | if (isIP(address) === 0) | 287 | 289 | throw new ERR_INVALID_ARG_VALUE('address', address); | 288 | 290 |
| |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-dns.js +18Lines changed: 18 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -344,6 +344,24 @@ dns.lookup('', { | 344 | 344 | }, err); | 345 | 345 | } | 346 | 346 |
| | 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 | + | 347 | 365 | [null, undefined, 65538, 'test', NaN, Infinity, Symbol(), 0n, true, false, '', () => {}, {}].forEach((port) => { | 348 | 366 | const err = { | 349 | 367 | code: 'ERR_SOCKET_BAD_PORT', | |
|