Skip to content

Commit 6a6112a

Browse files
benjamingrevanlucas
authored andcommitted
dns: Use object without protoype for map
Currently we use `{}` for the `lookup` function to find the relevant resolver to the dns.resolve function. It is preferable to use an object without a Object.prototype, currently for example you can do something like: ```js dns.resolve("google.com", "toString", console.log); ``` And get `[Object undefined]` logged and the callback would never be called. This is unexpected and strange behavior in my opinion. In addition, if someone adds a property to `Object.prototype` might also create unexpected results. This pull request fixes it, with it an appropriate error is thrown. PR-URL: #5843 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent ec18131 commit 6a6112a

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

lib/dns.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ function resolver(bindingName) {
240240
}
241241

242242

243-
var resolveMap = {};
243+
var resolveMap = Object.create(null);
244244
exports.resolve4 = resolveMap.A = resolver('queryA');
245245
exports.resolve6 = resolveMap.AAAA = resolver('queryAaaa');
246246
exports.resolveCname = resolveMap.CNAME = resolver('queryCname');

test/parallel/test-c-ares.js

+5
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ assert.throws(function() {
2727
dns.resolve('www.google.com', 'HI');
2828
}, /Unknown type/);
2929

30+
// Try calling resolve with an unsupported type that's an object key
31+
assert.throws(function() {
32+
dns.resolve('www.google.com', 'toString');
33+
}, /Unknown type/);
34+
3035
// Windows doesn't usually have an entry for localhost 127.0.0.1 in
3136
// C:\Windows\System32\drivers\etc\hosts
3237
// so we disable this test on Windows.

0 commit comments

Comments
 (0)