Skip to content

Commit

Permalink
src: make array arg length compile-time checkable
Browse files Browse the repository at this point in the history
PR-URL: #14122
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
bnoordhuis authored and Fishrock123 committed Jul 19, 2017
1 parent 3286f6a commit 36e1351
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions src/node_crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5314,7 +5314,7 @@ class PBKDF2Request : public AsyncWrap {
void Work();

static void After(uv_work_t* work_req, int status);
void After(Local<Value> argv[2]);
void After(Local<Value> (*argv)[2]);
void After();

private:
Expand Down Expand Up @@ -5352,14 +5352,14 @@ void PBKDF2Request::Work(uv_work_t* work_req) {
}


void PBKDF2Request::After(Local<Value> argv[2]) {
void PBKDF2Request::After(Local<Value> (*argv)[2]) {
if (error()) {
argv[0] = Undefined(env()->isolate());
argv[1] = Encode(env()->isolate(), key(), keylen(), BUFFER);
(*argv)[0] = Undefined(env()->isolate());
(*argv)[1] = Encode(env()->isolate(), key(), keylen(), BUFFER);
OPENSSL_cleanse(key(), keylen());
} else {
argv[0] = Exception::Error(env()->pbkdf2_error_string());
argv[1] = Undefined(env()->isolate());
(*argv)[0] = Exception::Error(env()->pbkdf2_error_string());
(*argv)[1] = Undefined(env()->isolate());
}
}

Expand All @@ -5368,7 +5368,7 @@ void PBKDF2Request::After() {
HandleScope handle_scope(env()->isolate());
Context::Scope context_scope(env()->context());
Local<Value> argv[2];
After(argv);
After(&argv);
MakeCallback(env()->ondone_string(), arraysize(argv), argv);
}

Expand Down Expand Up @@ -5485,7 +5485,7 @@ void PBKDF2(const FunctionCallbackInfo<Value>& args) {
env->PrintSyncTrace();
req->Work();
Local<Value> argv[2];
req->After(argv);
req->After(&argv);
delete req;

if (argv[0]->IsObject())
Expand Down Expand Up @@ -5595,21 +5595,21 @@ void RandomBytesWork(uv_work_t* work_req) {


// don't call this function without a valid HandleScope
void RandomBytesCheck(RandomBytesRequest* req, Local<Value> argv[2]) {
void RandomBytesCheck(RandomBytesRequest* req, Local<Value> (*argv)[2]) {
if (req->error()) {
char errmsg[256] = "Operation not supported";

if (req->error() != static_cast<unsigned long>(-1)) // NOLINT(runtime/int)
ERR_error_string_n(req->error(), errmsg, sizeof errmsg);

argv[0] = Exception::Error(OneByteString(req->env()->isolate(), errmsg));
argv[1] = Null(req->env()->isolate());
(*argv)[0] = Exception::Error(OneByteString(req->env()->isolate(), errmsg));
(*argv)[1] = Null(req->env()->isolate());
req->release();
} else {
char* data = nullptr;
size_t size;
req->return_memory(&data, &size);
argv[0] = Null(req->env()->isolate());
(*argv)[0] = Null(req->env()->isolate());
Local<Value> buffer =
req->object()->Get(req->env()->context(),
req->env()->buffer_string()).ToLocalChecked();
Expand All @@ -5618,9 +5618,9 @@ void RandomBytesCheck(RandomBytesRequest* req, Local<Value> argv[2]) {
CHECK_LE(req->size(), Buffer::Length(buffer));
char* buf = Buffer::Data(buffer);
memcpy(buf, data, req->size());
argv[1] = buffer;
(*argv)[1] = buffer;
} else {
argv[1] = Buffer::New(req->env(), data, size).ToLocalChecked();
(*argv)[1] = Buffer::New(req->env(), data, size).ToLocalChecked();
}
}
}
Expand All @@ -5634,22 +5634,22 @@ void RandomBytesAfter(uv_work_t* work_req, int status) {
HandleScope handle_scope(env->isolate());
Context::Scope context_scope(env->context());
Local<Value> argv[2];
RandomBytesCheck(req, argv);
RandomBytesCheck(req, &argv);
req->MakeCallback(env->ondone_string(), arraysize(argv), argv);
delete req;
}


void RandomBytesProcessSync(Environment* env,
RandomBytesRequest* req,
Local<Value> argv[2]) {
Local<Value> (*argv)[2]) {
env->PrintSyncTrace();
RandomBytesWork(req->work_req());
RandomBytesCheck(req, argv);
delete req;

if (!argv[0]->IsNull())
env->isolate()->ThrowException(argv[0]);
if (!(*argv)[0]->IsNull())
env->isolate()->ThrowException((*argv)[0]);
}


Expand Down Expand Up @@ -5686,7 +5686,7 @@ void RandomBytes(const FunctionCallbackInfo<Value>& args) {
args.GetReturnValue().Set(obj);
} else {
Local<Value> argv[2];
RandomBytesProcessSync(env, req, argv);
RandomBytesProcessSync(env, req, &argv);
if (argv[0]->IsNull())
args.GetReturnValue().Set(argv[1]);
}
Expand Down Expand Up @@ -5733,7 +5733,7 @@ void RandomBytesBuffer(const FunctionCallbackInfo<Value>& args) {
args.GetReturnValue().Set(obj);
} else {
Local<Value> argv[2];
RandomBytesProcessSync(env, req, argv);
RandomBytesProcessSync(env, req, &argv);
if (argv[0]->IsNull())
args.GetReturnValue().Set(argv[1]);
}
Expand Down

0 comments on commit 36e1351

Please sign in to comment.