Skip to content

Commit 70648f4

Browse files
cjihrigevanlucas
authored andcommitted
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: #8170 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Yorkie Liu <yorkiefixer@gmail.com>
1 parent b0619e8 commit 70648f4

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/dns.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,12 @@ exports.lookupService = function(host, port, callback) {
191191
if (isIP(host) === 0)
192192
throw new TypeError('"host" argument needs to be a valid IP address');
193193

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

197+
if (typeof callback !== 'function')
198+
throw new TypeError('"callback" argument must be a function');
199+
197200
port = +port;
198201
callback = makeAsync(callback);
199202

test/parallel/test-dns.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,3 +177,7 @@ assert.throws(function() {
177177
assert.throws(function() {
178178
dns.lookupService('0.0.0.0', 'test', noop);
179179
}, /"port" should be >= 0 and < 65536, got "test"/);
180+
181+
assert.throws(() => {
182+
dns.lookupService('0.0.0.0', 80, null);
183+
}, /^TypeError: "callback" argument must be a function$/);

0 commit comments

Comments
 (0)