Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e3538bb

Browse filesBrowse files
tniessentargos
authored andcommitted
src: fix abort in pbkdf2
Fixes: #38341 PR-URL: #38354 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent e389e86 commit e3538bb
Copy full SHA for e3538bb

File tree

Expand file treeCollapse file tree

2 files changed

+15
-9
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+15
-9
lines changed
Open diff view settings
Collapse file

‎src/crypto/crypto_pbkdf2.cc‎

Copy file name to clipboardExpand all lines: src/crypto/crypto_pbkdf2.cc
+3-9Lines changed: 3 additions & 9 deletions
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

Collapse file

‎test/parallel/test-crypto-pbkdf2.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-crypto-pbkdf2.js
+12Lines changed: 12 additions & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.