Skip to content

Commit cc9d5ab

Browse files
committed
C-Ares shouldn't iterate over all Object.prototype elements
and furthermore error out of one of them isn't a DNS option. Test case by Ben Lund <ben.lund@gmail.com>; additional help from Tim Caswell <tim@creationix.com>.
1 parent 715e119 commit cc9d5ab

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

src/node_cares.cc

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -422,22 +422,13 @@ Handle<Value> Channel::New(const Arguments& args) {
422422
}
423423

424424
Local<Object> options_o = Local<Object>::Cast(args[0]);
425-
Local<Array> keys = options_o->GetPropertyNames();
426-
int length = keys->Length();
427-
428-
for (int i = 0; i < length; ++i) {
429-
Local<String> opt = Local<String>::Cast(keys->Get(Integer::New(i)));
430-
431-
if (opt->Equals(String::New("SOCK_STATE_CB"))) {
432-
c->handle_->Set(callback_symbol, options_o->Get(opt));
433-
options.sock_state_cb_data = c;
434-
options.sock_state_cb = Channel::SockStateCb;
435-
optmask |= ARES_OPT_SOCK_STATE_CB;
436-
continue;
437-
}
438425

439-
return ThrowException(Exception::Error(
440-
String::New("Unknown Option")));
426+
Local<Value> cb = options_o->Get(String::NewSymbol("SOCK_STATE_CB"));
427+
if (!cb.IsEmpty()) {
428+
c->handle_->Set(callback_symbol, cb);
429+
options.sock_state_cb_data = c;
430+
options.sock_state_cb = Channel::SockStateCb;
431+
optmask |= ARES_OPT_SOCK_STATE_CB;
441432
}
442433
}
443434

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
var sys = require('sys');
2+
3+
//sys.puts('puts before');
4+
5+
Object.prototype.xadsadsdasasdxx = function () {
6+
};
7+
8+
sys.puts('puts after');

0 commit comments

Comments
 (0)