Skip to content

Commit

Permalink
dns: lookupService() callback must be a function
Browse files Browse the repository at this point in the history
lookupService() requires a callback function. This commit adds
a check to verify that the callback is actually a function.

PR-URL: #8170
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: Yorkie Liu <yorkiefixer@gmail.com>
  • Loading branch information
cjihrig authored and evanlucas committed Aug 24, 2016
1 parent b0619e8 commit 70648f4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,12 @@ exports.lookupService = function(host, port, callback) {
if (isIP(host) === 0)
throw new TypeError('"host" argument needs to be a valid IP address');

if (port == null || !isLegalPort(port))
if (!isLegalPort(port))
throw new TypeError(`"port" should be >= 0 and < 65536, got "${port}"`);

if (typeof callback !== 'function')
throw new TypeError('"callback" argument must be a function');

port = +port;
callback = makeAsync(callback);

Expand Down
4 changes: 4 additions & 0 deletions test/parallel/test-dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,7 @@ assert.throws(function() {
assert.throws(function() {
dns.lookupService('0.0.0.0', 'test', noop);
}, /"port" should be >= 0 and < 65536, got "test"/);

assert.throws(() => {
dns.lookupService('0.0.0.0', 80, null);
}, /^TypeError: "callback" argument must be a function$/);

0 comments on commit 70648f4

Please sign in to comment.