Skip to content

Commit fccdbc8

Browse files
authored
crypto: do not leak scrypt param check errors
Signed-off-by: lazerg <lazerg2@gmail.com> Assisted-by: Claude Code PR-URL: #66671 Fixes: #66668 Reviewed-By: Filip Skokan <panva.ip@gmail.com>
1 parent 1a885ca commit fccdbc8

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

‎src/crypto/crypto_scrypt.cc‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ Maybe<void> ScryptTraits::AdditionalConfig(
8585
params->length = args[offset + 6].As<Int32>()->Value();
8686
CHECK_GE(params->length, 0);
8787

88+
ncrypto::MarkPopErrorOnReturn mark_pop_error_on_return;
8889
if (!ncrypto::checkScryptParams(
8990
params->N, params->r, params->p, params->maxmem)) {
9091
// Do not use CryptoErrorStore or ThrowCryptoError here in order to maintain

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ if (!common.hasCrypto)
55

66
const assert = require('assert');
77
const crypto = require('crypto');
8+
const fixtures = require('../common/fixtures');
89
const { hasFIPS, isBoringSSL } = require('../common/crypto');
910
const isFips = hasFIPS(3);
1011

@@ -196,6 +197,19 @@ for (const options of toobig) {
196197
expected);
197198
}
198199

200+
// A failed parameter check must not leave an error on the OpenSSL error queue
201+
// for the next unrelated crypto operation to pick up.
202+
{
203+
const key = fixtures.readKey('ec_p256_private.pem');
204+
const options = { N: 2 ** 10, p: 1, r: 8, maxmem: 2 ** 20 };
205+
const expected = { code: 'ERR_CRYPTO_INVALID_SCRYPT_PARAMS' };
206+
assert.throws(() => crypto.scryptSync('pass', 'salt', 1, options), expected);
207+
crypto.createPrivateKey(key);
208+
assert.throws(() => crypto.scrypt('pass', 'salt', 1, options, () => {}),
209+
expected);
210+
crypto.createPrivateKey(key);
211+
}
212+
199213
if (!isFips) {
200214
const expected = '4cac4540';
201215
const actual = crypto.scryptSync('pass', 'salt', 4);

0 commit comments

Comments
 (0)