Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
dns: fix GetAddrInfo assert
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
trevnorris committed Aug 5, 2014
1 parent 4306786 commit e643fe4
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 8 deletions.
7 changes: 1 addition & 6 deletions lib/dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

This comment has been minimized.

Copy link
@orangemocha

orangemocha Aug 7, 2014

Contributor

Removing this else block broke passing an integer as the second argument (options). Was that the intention? If so the documentation (and tests) should be updated as well

This comment has been minimized.

Copy link
@trevnorris

trevnorris Aug 7, 2014

Author

My mistake. I glanced over family for options in the following if(), and figured that logic was no longer needed. You're correct. This shouldn't have been removed.

This comment has been minimized.

Copy link
@cjihrig

cjihrig Aug 8, 2014

Should be fixed by #8106

}

if (family !== 0 && family !== 4 && family !== 6)
Expand Down
3 changes: 1 addition & 2 deletions src/cares_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1014,12 +1014,11 @@ static void GetAddrInfo(const FunctionCallbackInfo<Value>& args) {
assert(args[0]->IsObject());
assert(args[1]->IsString());
assert(args[2]->IsInt32());
assert(args[3]->IsInt32());
Local<Object> req_wrap_obj = args[0].As<Object>();
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:
Expand Down

0 comments on commit e643fe4

Please sign in to comment.