From 6f584af7f58fd38054d7923525ea4143d24d68ba Mon Sep 17 00:00:00 2001 From: Benjamin Gruenbaum Date: Tue, 22 Mar 2016 15:40:36 +0200 Subject: [PATCH 1/2] 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. --- lib/dns.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/dns.js b/lib/dns.js index e77542457b5cd1..e165b1bc0d2f05 100644 --- a/lib/dns.js +++ b/lib/dns.js @@ -243,7 +243,7 @@ function resolver(bindingName) { } -var resolveMap = {}; +var resolveMap = Object.create(null); exports.resolve4 = resolveMap.A = resolver('queryA'); exports.resolve6 = resolveMap.AAAA = resolver('queryAaaa'); exports.resolveCname = resolveMap.CNAME = resolver('queryCname'); From 606fe5fef24205a1ed1ae9a12deadd49af038749 Mon Sep 17 00:00:00 2001 From: Benjamin Gruenbaum Date: Tue, 22 Mar 2016 17:15:37 +0200 Subject: [PATCH 2/2] add test --- test/parallel/test-c-ares.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/parallel/test-c-ares.js b/test/parallel/test-c-ares.js index 8c2178ead6a93d..66ae0e0a4adf33 100644 --- a/test/parallel/test-c-ares.js +++ b/test/parallel/test-c-ares.js @@ -27,6 +27,11 @@ assert.throws(function() { dns.resolve('www.google.com', 'HI'); }, /Unknown type/); +// Try calling resolve with an unsupported type that's an object key +assert.throws(function() { + dns.resolve('www.google.com', 'toString'); +}, /Unknown type/); + // Windows doesn't usually have an entry for localhost 127.0.0.1 in // C:\Windows\System32\drivers\etc\hosts // so we disable this test on Windows.