From f042929c3cdb2c5ccf46d0f599427f43e58f8c30 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Wed, 18 Apr 2018 15:21:03 +0800 Subject: [PATCH] src: throw ERR_INVALID_ARG_VALUE in node_crypto.cc PR-URL: https://github.com/nodejs/node/pull/20121 Reviewed-By: Daniel Bevenius Reviewed-By: Anna Henningsen Reviewed-By: Matteo Collina Reviewed-By: James M Snell Reviewed-By: Jeremiah Senkpiel --- src/node_crypto.cc | 9 ++++++--- src/node_errors.h | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/node_crypto.cc b/src/node_crypto.cc index fe6615d22b06bf..947db804d25424 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -956,7 +956,8 @@ void SecureContext::SetDHParam(const FunctionCallbackInfo& args) { DH_get0_pqg(dh, &p, nullptr, nullptr); const int size = BN_num_bits(p); if (size < 1024) { - return env->ThrowError("DH parameter is less than 1024 bits"); + return THROW_ERR_INVALID_ARG_VALUE( + env, "DH parameter is less than 1024 bits"); } else if (size < 2048) { args.GetReturnValue().Set(FIXED_ONE_BYTE_STRING( env->isolate(), "DH parameter is less than 2048 bits")); @@ -1203,7 +1204,8 @@ void SecureContext::SetTicketKeys(const FunctionCallbackInfo& args) { THROW_AND_RETURN_IF_NOT_BUFFER(env, args[0], "Ticket keys"); if (Buffer::Length(args[0]) != 48) { - return env->ThrowTypeError("Ticket keys length must be 48 bytes"); + return THROW_ERR_INVALID_ARG_VALUE( + env, "Ticket keys length must be 48 bytes"); } memcpy(wrap->ticket_key_name_, Buffer::Data(args[0]), 16); @@ -4391,7 +4393,8 @@ void ECDH::New(const FunctionCallbackInfo& args) { int nid = OBJ_sn2nid(*curve); if (nid == NID_undef) - return env->ThrowTypeError("First argument should be a valid curve name"); + return THROW_ERR_INVALID_ARG_VALUE(env, + "First argument should be a valid curve name"); EC_KEY* key = EC_KEY_new_by_curve_name(nid); if (key == nullptr) diff --git a/src/node_errors.h b/src/node_errors.h index 133fb3ab96dc8c..ae6a1c029d5f0c 100644 --- a/src/node_errors.h +++ b/src/node_errors.h @@ -19,6 +19,7 @@ namespace node { #define ERRORS_WITH_CODE(V) \ V(ERR_BUFFER_OUT_OF_BOUNDS, RangeError) \ V(ERR_INDEX_OUT_OF_RANGE, RangeError) \ + V(ERR_INVALID_ARG_VALUE, TypeError) \ V(ERR_INVALID_ARG_TYPE, TypeError) \ V(ERR_MEMORY_ALLOCATION_FAILED, Error) \ V(ERR_MISSING_MODULE, Error) \