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 86e3903

Browse filesBrowse files
benjamingrMyles Borins
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 <jasnell@gmail.com> Reviewed-By: Michaël Zasso <mic.besace@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent 940d204 commit 86e3903
Copy full SHA for 86e3903

File tree

Expand file treeCollapse file tree

2 files changed

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

2 files changed

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

‎lib/dns.js‎

Copy file name to clipboardExpand all lines: lib/dns.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ function resolver(bindingName) {
241241
}
242242

243243

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

‎test/parallel/test-c-ares.js‎

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