Skip to content

Commit

Permalink
C-Ares shouldn't iterate over all Object.prototype elements
Browse files Browse the repository at this point in the history
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>.
  • Loading branch information
ry committed Apr 11, 2010
1 parent 715e119 commit cc9d5ab
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
21 changes: 6 additions & 15 deletions src/node_cares.cc
Original file line number Diff line number Diff line change
Expand Up @@ -422,22 +422,13 @@ Handle<Value> Channel::New(const Arguments& args) {
}

Local<Object> options_o = Local<Object>::Cast(args[0]);
Local<Array> keys = options_o->GetPropertyNames();
int length = keys->Length();

for (int i = 0; i < length; ++i) {
Local<String> opt = Local<String>::Cast(keys->Get(Integer::New(i)));

if (opt->Equals(String::New("SOCK_STATE_CB"))) {
c->handle_->Set(callback_symbol, options_o->Get(opt));
options.sock_state_cb_data = c;
options.sock_state_cb = Channel::SockStateCb;
optmask |= ARES_OPT_SOCK_STATE_CB;
continue;
}

return ThrowException(Exception::Error(
String::New("Unknown Option")));
Local<Value> cb = options_o->Get(String::NewSymbol("SOCK_STATE_CB"));
if (!cb.IsEmpty()) {
c->handle_->Set(callback_symbol, cb);
options.sock_state_cb_data = c;
options.sock_state_cb = Channel::SockStateCb;
optmask |= ARES_OPT_SOCK_STATE_CB;
}
}

Expand Down
8 changes: 8 additions & 0 deletions test/simple/test-regression-object-prototype.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
var sys = require('sys');

//sys.puts('puts before');

Object.prototype.xadsadsdasasdxx = function () {
};

sys.puts('puts after');

0 comments on commit cc9d5ab

Please sign in to comment.