Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 70648f4

Browse filesBrowse 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
Copy full SHA for 70648f4

File tree

Expand file treeCollapse file tree

2 files changed

+8
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+8
-1
lines changed
Open diff view settings
Collapse file

‎lib/dns.js‎

Copy file name to clipboardExpand all lines: lib/dns.js
+4-1Lines 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

Collapse file

‎test/parallel/test-dns.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-dns.js
+4Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.