Skip to content

Commit

Permalink
src: throw ERR_MISSING_ARGS in node_crypto.cc
Browse files Browse the repository at this point in the history
PR-URL: #20121
Reviewed-By: Daniel Bevenius <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Jeremiah Senkpiel <[email protected]>
  • Loading branch information
joyeecheung authored and jasnell committed Apr 19, 2018
1 parent f042929 commit a6be27a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
32 changes: 17 additions & 15 deletions src/node_crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ void SecureContext::SetKey(const FunctionCallbackInfo<Value>& args) {

unsigned int len = args.Length();
if (len < 1) {
return env->ThrowError("Private key argument is mandatory");
return THROW_ERR_MISSING_ARGS(env, "Private key argument is mandatory");
}

if (len > 2) {
Expand Down Expand Up @@ -692,7 +692,7 @@ void SecureContext::SetCert(const FunctionCallbackInfo<Value>& args) {
ASSIGN_OR_RETURN_UNWRAP(&sc, args.Holder());

if (args.Length() != 1) {
return env->ThrowTypeError("Certificate argument is mandatory");
return THROW_ERR_MISSING_ARGS(env, "Certificate argument is mandatory");
}

BIO* bio = LoadBIO(env, args[0]);
Expand Down Expand Up @@ -766,7 +766,7 @@ void SecureContext::AddCACert(const FunctionCallbackInfo<Value>& args) {
ClearErrorOnReturn clear_error_on_return;

if (args.Length() != 1) {
return env->ThrowTypeError("CA certificate argument is mandatory");
return THROW_ERR_MISSING_ARGS(env, "CA certificate argument is mandatory");
}

BIO* bio = LoadBIO(env, args[0]);
Expand Down Expand Up @@ -797,7 +797,7 @@ void SecureContext::AddCRL(const FunctionCallbackInfo<Value>& args) {
ASSIGN_OR_RETURN_UNWRAP(&sc, args.Holder());

if (args.Length() != 1) {
return env->ThrowTypeError("CRL argument is mandatory");
return THROW_ERR_MISSING_ARGS(env, "CRL argument is mandatory");
}

ClearErrorOnReturn clear_error_on_return;
Expand Down Expand Up @@ -900,7 +900,7 @@ void SecureContext::SetCiphers(const FunctionCallbackInfo<Value>& args) {
ClearErrorOnReturn clear_error_on_return;

if (args.Length() != 1) {
return env->ThrowTypeError("Ciphers argument is mandatory");
return THROW_ERR_MISSING_ARGS(env, "Ciphers argument is mandatory");
}

THROW_AND_RETURN_IF_NOT_STRING(env, args[0], "Ciphers");
Expand All @@ -916,7 +916,7 @@ void SecureContext::SetECDHCurve(const FunctionCallbackInfo<Value>& args) {
Environment* env = sc->env();

if (args.Length() != 1)
return env->ThrowTypeError("ECDH curve name argument is mandatory");
return THROW_ERR_MISSING_ARGS(env, "ECDH curve name argument is mandatory");

THROW_AND_RETURN_IF_NOT_STRING(env, args[0], "ECDH curve name");

Expand All @@ -939,7 +939,7 @@ void SecureContext::SetDHParam(const FunctionCallbackInfo<Value>& args) {
// Auto DH is not supported in openssl 1.0.1, so dhparam needs
// to be specified explicitly
if (args.Length() != 1)
return env->ThrowTypeError("DH argument is mandatory");
return THROW_ERR_MISSING_ARGS(env, "DH argument is mandatory");

// Invalid dhparam is silently discarded and DHE is no longer used.
BIO* bio = LoadBIO(env, args[0]);
Expand Down Expand Up @@ -994,7 +994,8 @@ void SecureContext::SetSessionIdContext(
Environment* env = sc->env();

if (args.Length() != 1) {
return env->ThrowTypeError("Session ID context argument is mandatory");
return THROW_ERR_MISSING_ARGS(
env, "Session ID context argument is mandatory");
}

THROW_AND_RETURN_IF_NOT_STRING(env, args[0], "Session ID context");
Expand Down Expand Up @@ -1065,7 +1066,7 @@ void SecureContext::LoadPKCS12(const FunctionCallbackInfo<Value>& args) {
ClearErrorOnReturn clear_error_on_return;

if (args.Length() < 1) {
return env->ThrowTypeError("PFX certificate argument is mandatory");
return THROW_ERR_MISSING_ARGS(env, "PFX certificate argument is mandatory");
}

in = LoadBIO(env, args[0]);
Expand Down Expand Up @@ -1198,7 +1199,7 @@ void SecureContext::SetTicketKeys(const FunctionCallbackInfo<Value>& args) {
Environment* env = wrap->env();

if (args.Length() < 1) {
return env->ThrowTypeError("Ticket keys argument is mandatory");
return THROW_ERR_MISSING_ARGS(env, "Ticket keys argument is mandatory");
}

THROW_AND_RETURN_IF_NOT_BUFFER(env, args[0], "Ticket keys");
Expand Down Expand Up @@ -1951,7 +1952,7 @@ void SSLWrap<Base>::SetSession(const FunctionCallbackInfo<Value>& args) {
ASSIGN_OR_RETURN_UNWRAP(&w, args.Holder());

if (args.Length() < 1) {
return env->ThrowError("Session argument is mandatory");
return THROW_ERR_MISSING_ARGS(env, "Session argument is mandatory");
}

THROW_AND_RETURN_IF_NOT_BUFFER(env, args[0], "Session");
Expand Down Expand Up @@ -2076,7 +2077,7 @@ void SSLWrap<Base>::SetOCSPResponse(
Environment* env = w->env();

if (args.Length() < 1)
return env->ThrowTypeError("OCSP response argument is mandatory");
return THROW_ERR_MISSING_ARGS(env, "OCSP response argument is mandatory");

THROW_AND_RETURN_IF_NOT_BUFFER(env, args[0], "OCSP response");

Expand Down Expand Up @@ -4085,7 +4086,7 @@ void DiffieHellman::DiffieHellmanGroup(
DiffieHellman* diffieHellman = new DiffieHellman(env, args.This());

if (args.Length() != 1) {
return env->ThrowError("Group name argument is mandatory");
return THROW_ERR_MISSING_ARGS(env, "Group name argument is mandatory");
}

THROW_AND_RETURN_IF_NOT_STRING(env, args[0], "Group name");
Expand Down Expand Up @@ -4235,7 +4236,8 @@ void DiffieHellman::ComputeSecret(const FunctionCallbackInfo<Value>& args) {
BIGNUM* key = nullptr;

if (args.Length() == 0) {
return env->ThrowError("Other party's public key argument is mandatory");
return THROW_ERR_MISSING_ARGS(
env, "Other party's public key argument is mandatory");
} else {
THROW_AND_RETURN_IF_NOT_BUFFER(env, args[0], "Other party's public key");
key = BN_bin2bn(
Expand Down Expand Up @@ -4305,7 +4307,7 @@ void DiffieHellman::SetKey(const v8::FunctionCallbackInfo<v8::Value>& args,

if (args.Length() == 0) {
snprintf(errmsg, sizeof(errmsg), "%s argument is mandatory", what);
return env->ThrowError(errmsg);
return THROW_ERR_MISSING_ARGS(env, errmsg);
}

if (!Buffer::HasInstance(args[0])) {
Expand Down
1 change: 1 addition & 0 deletions src/node_errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace node {
V(ERR_INVALID_ARG_VALUE, TypeError) \
V(ERR_INVALID_ARG_TYPE, TypeError) \
V(ERR_MEMORY_ALLOCATION_FAILED, Error) \
V(ERR_MISSING_ARGS, TypeError) \
V(ERR_MISSING_MODULE, Error) \
V(ERR_STRING_TOO_LONG, Error) \
V(ERR_BUFFER_TOO_LARGE, Error)
Expand Down

0 comments on commit a6be27a

Please sign in to comment.