From 46631b5ae575c3dd93f301f9d9a1e65526ca564c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Tue, 4 Apr 2023 15:57:24 +0000 Subject: [PATCH] crypto: replace THROW with CHECK for scrypt keylen The JS layer already uses validateInt32(keylen, 'keylen', 0) to ensure that the keylen argument fits into a signed 32-bit integer, thus, the THROW statement in C++ is unreachable (unless the binding is accessed directly, of course). --- src/crypto/crypto_scrypt.cc | 5 +---- test/parallel/test-crypto-scrypt.js | 8 ++++++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/crypto/crypto_scrypt.cc b/src/crypto/crypto_scrypt.cc index 88d355446c0984..4dae07f13604d4 100644 --- a/src/crypto/crypto_scrypt.cc +++ b/src/crypto/crypto_scrypt.cc @@ -109,10 +109,7 @@ Maybe ScryptTraits::AdditionalConfig( } params->length = args[offset + 6].As()->Value(); - if (params->length < 0) { - THROW_ERR_OUT_OF_RANGE(env, "length must be <= %d", INT_MAX); - return Nothing(); - } + CHECK_GE(params->length, 0); return Just(true); } diff --git a/test/parallel/test-crypto-scrypt.js b/test/parallel/test-crypto-scrypt.js index 63656e056f195a..73bf0217b1fb67 100644 --- a/test/parallel/test-crypto-scrypt.js +++ b/test/parallel/test-crypto-scrypt.js @@ -143,10 +143,18 @@ const badargs = [ args: ['', '', -42], expected: { code: 'ERR_OUT_OF_RANGE', message: /"keylen"/ }, }, + { + args: ['', '', 2 ** 31], + expected: { code: 'ERR_OUT_OF_RANGE', message: /"keylen"/ }, + }, { args: ['', '', 2147485780], expected: { code: 'ERR_OUT_OF_RANGE', message: /"keylen"/ }, }, + { + args: ['', '', 2 ** 32], + expected: { code: 'ERR_OUT_OF_RANGE', message: /"keylen"/ }, + }, ]; for (const options of good) {