summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBen Noordhuis <info@bnoordhuis.nl>2012-09-03 23:09:17 +0200
committerBen Noordhuis <info@bnoordhuis.nl>2012-09-03 23:33:02 +0200
commitd1eff9ab68ae3fa32285544ad9f1d2c2ed52ab82 (patch)
tree711e30d2d6ded06c7a6be70e2c266043264ada27 /src
parentea1cba6246a8b1784e22d076139b9244a9ff42f8 (diff)
downloadnodejs-d1eff9ab68ae3fa32285544ad9f1d2c2ed52ab82.tar.gz
nodejs-d1eff9ab68ae3fa32285544ad9f1d2c2ed52ab82.tar.bz2
nodejs-d1eff9ab68ae3fa32285544ad9f1d2c2ed52ab82.zip
crypto: make randomBytes() compatible with domains
Don't execute the callback in the context of the global object. MakeCallback() tries to apply the active domain to the callback. If the user polluted the global object with a 'domain' property, as in the code example below, MakeCallback() will try to apply that. Example: domain = {}; // missing var keyword is intentional crypto.randomBytes(8, cb); // TypeError: undefined is not a function Fixes #3956.
Diffstat (limited to 'src')
-rw-r--r--src/node_crypto.cc22
1 files changed, 8 insertions, 14 deletions
diff --git a/src/node_crypto.cc b/src/node_crypto.cc
index 5b21e55a8..dc5da802b 100644
--- a/src/node_crypto.cc
+++ b/src/node_crypto.cc
@@ -4354,7 +4354,7 @@ typedef int (*RandomBytesGenerator)(unsigned char* buf, int size);
struct RandomBytesRequest {
~RandomBytesRequest();
- Persistent<Function> callback_;
+ Persistent<Object> obj_;
unsigned long error_; // openssl error code or zero
uv_work_t work_req_;
size_t size_;
@@ -4363,10 +4363,9 @@ struct RandomBytesRequest {
RandomBytesRequest::~RandomBytesRequest() {
- if (!callback_.IsEmpty()) {
- callback_.Dispose();
- callback_.Clear();
- }
+ if (obj_.IsEmpty()) return;
+ obj_.Dispose();
+ obj_.Clear();
}
@@ -4427,12 +4426,7 @@ void RandomBytesAfter(uv_work_t* work_req) {
HandleScope scope;
Local<Value> argv[2];
RandomBytesCheck(req, argv);
-
- // XXX There should be an object connected to this that
- // we can attach a domain onto.
- MakeCallback(Context::GetCurrent()->Global(),
- req->callback_,
- ARRAY_SIZE(argv), argv);
+ MakeCallback(req->obj_, "ondone", ARRAY_SIZE(argv), argv);
delete req;
}
@@ -4457,15 +4451,15 @@ Handle<Value> RandomBytes(const Arguments& args) {
req->size_ = size;
if (args[1]->IsFunction()) {
- Local<Function> callback_v = Local<Function>(Function::Cast(*args[1]));
- req->callback_ = Persistent<Function>::New(callback_v);
+ req->obj_ = Persistent<Object>::New(Object::New());
+ req->obj_->Set(String::New("ondone"), args[1]);
uv_queue_work(uv_default_loop(),
&req->work_req_,
RandomBytesWork<generator>,
RandomBytesAfter<generator>);
- return Undefined();
+ return req->obj_;
}
else {
Local<Value> argv[2];