diff --git a/src/crypto/crypto_pbkdf2.cc b/src/crypto/crypto_pbkdf2.cc index cc9a0d072ad13c..495722927ab5be 100644 --- a/src/crypto/crypto_pbkdf2.cc +++ b/src/crypto/crypto_pbkdf2.cc @@ -92,26 +92,20 @@ Maybe PBKDF2Traits::AdditionalConfig( params->iterations = args[offset + 2].As()->Value(); if (params->iterations < 0) { - char msg[1024]; - snprintf(msg, sizeof(msg), "iterations must be <= %d", INT_MAX); - THROW_ERR_OUT_OF_RANGE(env, msg); + THROW_ERR_OUT_OF_RANGE(env, "iterations must be <= %d", INT_MAX); return Nothing(); } params->length = args[offset + 3].As()->Value(); if (params->length < 0) { - char msg[1024]; - snprintf(msg, sizeof(msg), "length must be <= %d", INT_MAX); - THROW_ERR_OUT_OF_RANGE(env, msg); + THROW_ERR_OUT_OF_RANGE(env, "length must be <= %d", INT_MAX); return Nothing(); } Utf8Value name(args.GetIsolate(), args[offset + 4]); params->digest = EVP_get_digestbyname(*name); if (params->digest == nullptr) { - char errmsg[1024]; - snprintf(errmsg, sizeof(errmsg), "Invalid digest: %s", *name); - THROW_ERR_CRYPTO_INVALID_DIGEST(env, errmsg); + THROW_ERR_CRYPTO_INVALID_DIGEST(env, "Invalid digest: %s", *name); return Nothing(); } diff --git a/test/parallel/test-crypto-pbkdf2.js b/test/parallel/test-crypto-pbkdf2.js index 260bdd394ce05e..c9ab6a9c48438e 100644 --- a/test/parallel/test-crypto-pbkdf2.js +++ b/test/parallel/test-crypto-pbkdf2.js @@ -231,3 +231,15 @@ if (!common.hasOpenSSL3) { runPBKDF2(new Uint8Array(10), 'salt', 8, 8, hash); }); } + +{ + // This should not crash. + assert.throws( + () => crypto.pbkdf2Sync('1', '2', 1, 1, '%'), + { + code: 'ERR_CRYPTO_INVALID_DIGEST', + name: 'TypeError', + message: 'Invalid digest: %' + } + ); +}