Visitar URL original
crypto: replace THROW with CHECK for scrypt keylen · nodejs/node@48c0148 · GitHub
The Wayback Machine - https://web.archive.org/web/20230426010631/https://github.com/nodejs/node/commit/48c01485cd
Skip to content
Permalink
Browse files
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).

PR-URL: #47407
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information
tniessen authored and RafaelGSS committed Apr 13, 2023
1 parent 3fc1147 commit 48c0148
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
@@ -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);
}
@@ -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) {

0 comments on commit 48c0148

Please sign in to comment.