Browse Source

dns: lookupService() callback must be a function

lookupService() requires a callback function. This commit adds
a check to verify that the callback is actually a function.

PR-URL: https://github.com/nodejs/node/pull/8170
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: Yorkie Liu <yorkiefixer@gmail.com>
v7.x
cjihrig 8 years ago
committed by James M Snell
parent
commit
3a43568020
  1. 5
      lib/dns.js
  2. 4
      test/parallel/test-dns.js

5
lib/dns.js

@ -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);

4
test/parallel/test-dns.js

@ -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$/);

Loading…
Cancel
Save