summaryrefslogtreecommitdiff
path: root/lib/dns.js
diff options
context:
space:
mode:
authorcjihrig <cjihrig@gmail.com>2016-09-16 14:08:56 -0400
committercjihrig <cjihrig@gmail.com>2016-09-20 19:56:13 -0400
commitb176d30a691f5b04dd9fef99c1ca21e548384b36 (patch)
tree32a6b5dc016320b940b8845f5a582e69544d75d7 /lib/dns.js
parentd4bf5cac435e8e54144cc481d61b86db5aa11da7 (diff)
downloadandroid-node-v8-b176d30a691f5b04dd9fef99c1ca21e548384b36.tar.gz
android-node-v8-b176d30a691f5b04dd9fef99c1ca21e548384b36.tar.bz2
android-node-v8-b176d30a691f5b04dd9fef99c1ca21e548384b36.zip
dns: handle array holes in setServers()
This commit adds better handling of exceptional array formats passed to dns.setServers(). Prior to this commit, the input array was validated using map(), which preserves holes, allowing them to be passed to c-ares, crashing Node. This commit replaces map() with forEach(), which skips holes. Fixes: https://github.com/nodejs/node/issues/8538 PR-URL: https://github.com/nodejs/node/pull/8567 Reviewed-By: Ilkka Myller <ilkka.myller@nodefield.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'lib/dns.js')
-rw-r--r--lib/dns.js9
1 files changed, 5 insertions, 4 deletions
diff --git a/lib/dns.js b/lib/dns.js
index 7c76aebb97..55351bb774 100644
--- a/lib/dns.js
+++ b/lib/dns.js
@@ -286,25 +286,26 @@ exports.setServers = function(servers) {
// cache the original servers because in the event of an error setting the
// servers cares won't have any servers available for resolution
const orig = cares.getServers();
+ const newSet = [];
- const newSet = servers.map((serv) => {
+ servers.forEach((serv) => {
var ipVersion = isIP(serv);
if (ipVersion !== 0)
- return [ipVersion, serv];
+ return newSet.push([ipVersion, serv]);
const match = serv.match(/\[(.*)\](:\d+)?/);
// we have an IPv6 in brackets
if (match) {
ipVersion = isIP(match[1]);
if (ipVersion !== 0)
- return [ipVersion, match[1]];
+ return newSet.push([ipVersion, match[1]]);
}
const s = serv.split(/:\d+$/)[0];
ipVersion = isIP(s);
if (ipVersion !== 0)
- return [ipVersion, s];
+ return newSet.push([ipVersion, s]);
throw new Error(`IP address is not properly formatted: ${serv}`);
});