Browse Source

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>.
v0.7.4-release
Ryan Dahl 15 years ago
parent
commit
cc9d5ab546
  1. 21
      src/node_cares.cc
  2. 8
      test/simple/test-regression-object-prototype.js

21
src/node_cares.cc

@ -422,22 +422,13 @@ Handle<Value> Channel::New(const Arguments& args) {
} }
Local<Object> options_o = Local<Object>::Cast(args[0]); 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( Local<Value> cb = options_o->Get(String::NewSymbol("SOCK_STATE_CB"));
String::New("Unknown Option"))); 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;
} }
} }

8
test/simple/test-regression-object-prototype.js

@ -0,0 +1,8 @@
var sys = require('sys');
//sys.puts('puts before');
Object.prototype.xadsadsdasasdxx = function () {
};
sys.puts('puts after');
Loading…
Cancel
Save