GeezerVison is showing github.com — dns: validate address type in lookupService · nodejs/node@152a326
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 |
|---|
@@ -83,6 +83,7 @@ const { | 83 | 83 | validateNumber, | 84 | 84 | validateOneOf, | 85 | 85 | validatePort, | | 86 | + validateString, | 86 | 87 | validateStringWithoutNullBytes, | 87 | 88 | } = require('internal/validators'); | 88 | 89 |
| @@ -269,6 +270,8 @@ function lookupService(address, port, callback) { | 269 | 270 | if (arguments.length !== 3) | 270 | 271 | throw new ERR_MISSING_ARGS('address', 'port', 'callback'); | 271 | 272 |
| | 273 | + validateString(address, 'address'); | | 274 | + | 272 | 275 | if (isIP(address) === 0) | 273 | 276 | throw new ERR_INVALID_ARG_VALUE('address', address); | 274 | 277 |
| |
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 |
|---|
@@ -282,6 +282,8 @@ function lookupService(address, port) { | 282 | 282 | if (arguments.length !== 2) | 283 | 283 | throw new ERR_MISSING_ARGS('address', 'port'); | 284 | 284 |
| | 285 | + validateString(address, 'address'); | | 286 | + | 285 | 287 | if (isIP(address) === 0) | 286 | 288 | throw new ERR_INVALID_ARG_VALUE('address', address); | 287 | 289 |
| |
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 |
|---|
@@ -394,6 +394,24 @@ assert.throws(() => { | 394 | 394 | }, err); | 395 | 395 | } | 396 | 396 |
| | 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 | + | 397 | 415 | [null, undefined, 65538, 'test', NaN, Infinity, Symbol(), 0n, true, false, '', () => {}, {}].forEach((port) => { | 398 | 416 | const err = { | 399 | 417 | code: 'ERR_SOCKET_BAD_PORT', | |
|