Skip to content

Commit

Permalink
crypto: replace THROW with CHECK for scrypt keylen
Browse files Browse the repository at this point in the history
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).

PR-URL: nodejs#47407
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Filip Skokan <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
  • Loading branch information
tniessen authored and MoLow committed Jul 6, 2023
1 parent 64a5fe0 commit a5f214c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 1 addition & 4 deletions src/crypto/crypto_scrypt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,7 @@ Maybe<bool> ScryptTraits::AdditionalConfig(
}

params->length = args[offset + 6].As<Int32>()->Value();
if (params->length < 0) {
THROW_ERR_OUT_OF_RANGE(env, "length must be <= %d", INT_MAX);
return Nothing<bool>();
}
CHECK_GE(params->length, 0);

return Just(true);
}
Expand Down
8 changes: 8 additions & 0 deletions test/parallel/test-crypto-scrypt.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit a5f214c

Please sign in to comment.