Skip to content

Commit 1cda3f3

Browse files
authored
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 <[email protected]> Reviewed-By: Filip Skokan <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent c311dc4 commit 1cda3f3

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/crypto/crypto_scrypt.cc

+1-4
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,7 @@ Maybe<bool> ScryptTraits::AdditionalConfig(
109109
}
110110

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

117114
return Just(true);
118115
}

test/parallel/test-crypto-scrypt.js

+8
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,18 @@ const badargs = [
143143
args: ['', '', -42],
144144
expected: { code: 'ERR_OUT_OF_RANGE', message: /"keylen"/ },
145145
},
146+
{
147+
args: ['', '', 2 ** 31],
148+
expected: { code: 'ERR_OUT_OF_RANGE', message: /"keylen"/ },
149+
},
146150
{
147151
args: ['', '', 2147485780],
148152
expected: { code: 'ERR_OUT_OF_RANGE', message: /"keylen"/ },
149153
},
154+
{
155+
args: ['', '', 2 ** 32],
156+
expected: { code: 'ERR_OUT_OF_RANGE', message: /"keylen"/ },
157+
},
150158
];
151159

152160
for (const options of good) {

0 commit comments

Comments
 (0)