Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ const {
validateNumber,
validateOneOf,
validatePort,
validateString,
validateStringWithoutNullBytes,
} = require('internal/validators');

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

validateString(address, 'address');

if (isIP(address) === 0)
throw new ERR_INVALID_ARG_VALUE('address', address);

Expand Down
2 changes: 2 additions & 0 deletions lib/internal/dns/promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,8 @@ function lookupService(address, port) {
if (arguments.length !== 2)
throw new ERR_MISSING_ARGS('address', 'port');

validateString(address, 'address');

if (isIP(address) === 0)
throw new ERR_INVALID_ARG_VALUE('address', address);

Expand Down
18 changes: 18 additions & 0 deletions test/parallel/test-dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,24 @@ assert.throws(() => {
}, err);
}

{
const invalidAddress = Buffer.from('127.0.0.1');
const err = {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "address" argument must be of type string. ' +
'Received an instance of Buffer'
};

assert.throws(() => {
dnsPromises.lookupService(invalidAddress, 0);
}, err);

assert.throws(() => {
dns.lookupService(invalidAddress, 0, common.mustNotCall());
}, err);
}

[null, undefined, 65538, 'test', NaN, Infinity, Symbol(), 0n, true, false, '', () => {}, {}].forEach((port) => {
const err = {
code: 'ERR_SOCKET_BAD_PORT',
Expand Down
Loading