From 0a4ff2f9a03e55d85c40e2e976c871908723cff0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Wed, 22 Mar 2023 12:41:15 +0100 Subject: [PATCH] src: replace impossible THROW with CHECK The JS layer already verifies that divisor_bits is either a non-negative 32-bit signed integer or null/undefined, in which case it passes -1 to the C++ layer. In either case, the C++ layer receives a 32-bit signed integer greater than or equal to -1. PR-URL: https://github.com/nodejs/node/pull/47168 Reviewed-By: Darshan Sen Reviewed-By: Luigi Pinca --- src/crypto/crypto_dsa.cc | 6 +----- test/parallel/test-crypto-keygen.js | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/crypto/crypto_dsa.cc b/src/crypto/crypto_dsa.cc index 6839283fbf4ca7..3fa4a415dc911a 100644 --- a/src/crypto/crypto_dsa.cc +++ b/src/crypto/crypto_dsa.cc @@ -83,16 +83,12 @@ Maybe DsaKeyGenTraits::AdditionalConfig( const FunctionCallbackInfo& args, unsigned int* offset, DsaKeyPairGenConfig* params) { - Environment* env = Environment::GetCurrent(args); CHECK(args[*offset]->IsUint32()); // modulus bits CHECK(args[*offset + 1]->IsInt32()); // divisor bits params->params.modulus_bits = args[*offset].As()->Value(); params->params.divisor_bits = args[*offset + 1].As()->Value(); - if (params->params.divisor_bits < -1) { - THROW_ERR_OUT_OF_RANGE(env, "invalid value for divisor_bits"); - return Nothing(); - } + CHECK_GE(params->params.divisor_bits, -1); *offset += 2; diff --git a/test/parallel/test-crypto-keygen.js b/test/parallel/test-crypto-keygen.js index 1a77266b057041..df8c5d93a90342 100644 --- a/test/parallel/test-crypto-keygen.js +++ b/test/parallel/test-crypto-keygen.js @@ -1278,7 +1278,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher); } // Test invalid divisor lengths. (out of range) - for (const divisorLength of [-6, -9, 2147483648]) { + for (const divisorLength of [-1, -6, -9, 2147483648]) { assert.throws(() => generateKeyPair('dsa', { modulusLength: 2048, divisorLength