Skip to content

Commit e643fe4

Browse files
committed
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 <trev.norris@gmail.com>
1 parent 4306786 commit e643fe4

2 files changed

Lines changed: 2 additions & 8 deletions

File tree

lib/dns.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,14 @@ function onlookup(err, addresses) {
102102
// lookup(hostname, [options,] callback)
103103
exports.lookup = function lookup(hostname, options, callback) {
104104
var hints = 0;
105-
var family;
105+
var family = 0;
106106

107107
// Parse arguments
108108
if (typeof options === 'function') {
109109
callback = options;
110110
family = 0;
111-
// Allow user to pass falsy values to options, and still pass callback.
112111
} else if (typeof callback !== 'function') {
113112
throw TypeError('invalid arguments: callback must be passed');
114-
} else if (!options) {
115-
family = 0;
116113
} else if (util.isObject(options)) {
117114
hints = options.hints >>> 0;
118115
family = options.family >>> 0;
@@ -123,8 +120,6 @@ exports.lookup = function lookup(hostname, options, callback) {
123120
hints !== (exports.ADDRCONFIG | exports.V4MAPPED)) {
124121
throw new TypeError('invalid argument: hints must use valid flags');
125122
}
126-
} else {
127-
family = options >>> 0;
128123
}
129124

130125
if (family !== 0 && family !== 4 && family !== 6)

src/cares_wrap.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,12 +1014,11 @@ static void GetAddrInfo(const FunctionCallbackInfo<Value>& args) {
10141014
assert(args[0]->IsObject());
10151015
assert(args[1]->IsString());
10161016
assert(args[2]->IsInt32());
1017-
assert(args[3]->IsInt32());
10181017
Local<Object> req_wrap_obj = args[0].As<Object>();
10191018
node::Utf8Value hostname(args[1]);
10201019

1020+
int32_t flags = (args[3]->IsInt32()) ? args[3]->Int32Value() : 0;
10211021
int family;
1022-
int32_t flags = args[3]->Int32Value();
10231022

10241023
switch (args[2]->Int32Value()) {
10251024
case 0:

0 commit comments

Comments
 (0)