Skip to content

Commit 234ce29

Browse files
committed
crypto: add NULL checks for OpenSSL allocation functions
Replace CHECK() assertions with graceful error handling for EVP_CIPHER_CTX_new() allocations that could fail under memory pressure: - crypto_aes.cc (AES_Cipher): return FAILED status - crypto_cipher.cc (CommonInit): throw JS error via ThrowCryptoError Fixes #62774
1 parent a962e72 commit 234ce29

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

src/crypto/crypto_aes.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ WebCryptoCipherStatus AES_Cipher(Environment* env,
4848
CHECK_EQ(key_data.GetKeyType(), kKeyTypeSecret);
4949

5050
auto ctx = CipherCtxPointer::New();
51-
CHECK(ctx);
51+
if (!ctx) {
52+
return WebCryptoCipherStatus::FAILED;
53+
}
5254

5355
if (params.cipher.isWrapMode()) {
5456
ctx.setAllowWrap();

src/crypto/crypto_cipher.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,9 @@ void CipherBase::CommonInit(const char* cipher_type,
338338
MarkPopErrorOnReturn mark_pop_error_on_return;
339339
CHECK(!ctx_);
340340
ctx_ = CipherCtxPointer::New();
341-
CHECK(ctx_);
341+
if (!ctx_) {
342+
return ThrowCryptoError(env(), ERR_get_error(), "Failed to allocate cipher context");
343+
}
342344

343345
if (cipher.isWrapMode()) {
344346
ctx_.setAllowWrap();

0 commit comments

Comments
 (0)