Skip to content

Commit 78ab09a

Browse files
committed
crypto,quic: add NULL checks for OpenSSL allocation functions
Replace CHECK() assertions with graceful error handling for EVP_CIPHER_CTX_new() allocation failures. - src/crypto/crypto_aes.cc: In AES_Cipher(), replace CHECK(ctx) with early return of WebCryptoCipherStatus::FAILED, matching the pattern already used in AES_CTR_Cipher2() in the same file. - src/crypto/crypto_cipher.cc: In CipherBase::CommonInit(), replace CHECK(ctx_) with ThrowCryptoError(), matching the error handling pattern used elsewhere in the function. Note: The other locations mentioned in #62774 (AES_CTR_Cipher2, TLSSession::Initialize, and ECKeyExportTraits::DoExport) already have proper NULL checks in the current codebase or have been refactored such that the relevant code no longer exists. Fixes: #62774
1 parent a962e72 commit 78ab09a

2 files changed

Lines changed: 8 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: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,11 @@ 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(),
343+
mark_pop_error_on_return.peekError(),
344+
"Failed to allocate cipher context");
345+
}
342346

343347
if (cipher.isWrapMode()) {
344348
ctx_.setAllowWrap();

0 commit comments

Comments
 (0)