Skip to content

Commit e3538bb

Browse files
tniessentargos
authored andcommitted
src: fix abort in pbkdf2
Fixes: #38341 PR-URL: #38354 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Filip Skokan <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent e389e86 commit e3538bb

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

src/crypto/crypto_pbkdf2.cc

+3-9
Original file line numberDiff line numberDiff line change
@@ -92,26 +92,20 @@ Maybe<bool> PBKDF2Traits::AdditionalConfig(
9292

9393
params->iterations = args[offset + 2].As<Int32>()->Value();
9494
if (params->iterations < 0) {
95-
char msg[1024];
96-
snprintf(msg, sizeof(msg), "iterations must be <= %d", INT_MAX);
97-
THROW_ERR_OUT_OF_RANGE(env, msg);
95+
THROW_ERR_OUT_OF_RANGE(env, "iterations must be <= %d", INT_MAX);
9896
return Nothing<bool>();
9997
}
10098

10199
params->length = args[offset + 3].As<Int32>()->Value();
102100
if (params->length < 0) {
103-
char msg[1024];
104-
snprintf(msg, sizeof(msg), "length must be <= %d", INT_MAX);
105-
THROW_ERR_OUT_OF_RANGE(env, msg);
101+
THROW_ERR_OUT_OF_RANGE(env, "length must be <= %d", INT_MAX);
106102
return Nothing<bool>();
107103
}
108104

109105
Utf8Value name(args.GetIsolate(), args[offset + 4]);
110106
params->digest = EVP_get_digestbyname(*name);
111107
if (params->digest == nullptr) {
112-
char errmsg[1024];
113-
snprintf(errmsg, sizeof(errmsg), "Invalid digest: %s", *name);
114-
THROW_ERR_CRYPTO_INVALID_DIGEST(env, errmsg);
108+
THROW_ERR_CRYPTO_INVALID_DIGEST(env, "Invalid digest: %s", *name);
115109
return Nothing<bool>();
116110
}
117111

test/parallel/test-crypto-pbkdf2.js

+12
Original file line numberDiff line numberDiff line change
@@ -231,3 +231,15 @@ if (!common.hasOpenSSL3) {
231231
runPBKDF2(new Uint8Array(10), 'salt', 8, 8, hash);
232232
});
233233
}
234+
235+
{
236+
// This should not crash.
237+
assert.throws(
238+
() => crypto.pbkdf2Sync('1', '2', 1, 1, '%'),
239+
{
240+
code: 'ERR_CRYPTO_INVALID_DIGEST',
241+
name: 'TypeError',
242+
message: 'Invalid digest: %'
243+
}
244+
);
245+
}

0 commit comments

Comments
 (0)