dns: verify argument is valid function in resolve
authorKenan Sulayman <kenan@sly.mn>
Fri, 7 Feb 2014 17:18:27 +0000 (18:18 +0100)
committerFedor Indutny <fedor.indutny@gmail.com>
Fri, 7 Feb 2014 22:10:01 +0000 (02:10 +0400)
Don't use argument as callback if it's not a valid callback function.
Throw a valid exception instead explaining the issue. Adds to #7070
("DNS — Throw meaningful error(s)").

lib/dns.js

index 15ee6a4..dcf2128 100644 (file)
@@ -184,9 +184,11 @@ exports.resolve = function(domain, type_, callback_) {
   if (typeof type_ == 'string') {
     resolver = resolveMap[type_];
     callback = callback_;
-  } else {
+  } else if (util.isFunction(type_)) {
     resolver = exports.resolve4;
     callback = type_;
+  } else {
+    throw new Error('Type must be a string')
   }
 
   if (typeof resolver === 'function') {