From e643fe4c4b79f2683914c6435f7166fc6be9f1a7 Mon Sep 17 00:00:00 2001 From: Trevor Norris Date: Mon, 4 Aug 2014 18:12:54 -0700 Subject: [PATCH] dns: fix GetAddrInfo assert The method GetAddrInfo() is used by more than just dns.lookup(), and in those cases a third argument isn't passed. This caused the following check to abort: assert(args[3]->IsInt32()); Fixes: 4306786 "net: don't prefer IPv4 addresses during resolution" Signed-off-by: Trevor Norris --- lib/dns.js | 7 +------ src/cares_wrap.cc | 3 +-- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/lib/dns.js b/lib/dns.js index dfe37dffd2..b891c79d52 100644 --- a/lib/dns.js +++ b/lib/dns.js @@ -102,17 +102,14 @@ function onlookup(err, addresses) { // lookup(hostname, [options,] callback) exports.lookup = function lookup(hostname, options, callback) { var hints = 0; - var family; + var family = 0; // Parse arguments if (typeof options === 'function') { callback = options; family = 0; - // Allow user to pass falsy values to options, and still pass callback. } else if (typeof callback !== 'function') { throw TypeError('invalid arguments: callback must be passed'); - } else if (!options) { - family = 0; } else if (util.isObject(options)) { hints = options.hints >>> 0; family = options.family >>> 0; @@ -123,8 +120,6 @@ exports.lookup = function lookup(hostname, options, callback) { hints !== (exports.ADDRCONFIG | exports.V4MAPPED)) { throw new TypeError('invalid argument: hints must use valid flags'); } - } else { - family = options >>> 0; } if (family !== 0 && family !== 4 && family !== 6) diff --git a/src/cares_wrap.cc b/src/cares_wrap.cc index af72c49595..f3911df5ce 100644 --- a/src/cares_wrap.cc +++ b/src/cares_wrap.cc @@ -1014,12 +1014,11 @@ static void GetAddrInfo(const FunctionCallbackInfo& args) { assert(args[0]->IsObject()); assert(args[1]->IsString()); assert(args[2]->IsInt32()); - assert(args[3]->IsInt32()); Local req_wrap_obj = args[0].As(); node::Utf8Value hostname(args[1]); + int32_t flags = (args[3]->IsInt32()) ? args[3]->Int32Value() : 0; int family; - int32_t flags = args[3]->Int32Value(); switch (args[2]->Int32Value()) { case 0: