Skip to content

Commit b7db0e3

Browse files
author
RoomWithOutRoof
committed
crypto: replace CHECK with NULL checks for EVP_CIPHER_CTX_new allocations
Replace CHECK() assertions with proper NULL checks and error returns for EVP_CIPHER_CTX_new() allocations. CHECK() causes an abort() on failure, which is not appropriate for recoverable allocation failures. Instead, return a failure status or throw a proper crypto error. Fixes: #62774
1 parent 58a8e1d commit b7db0e3

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+
"EVP_CIPHER_CTX_new");
345+
}
342346

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

0 commit comments

Comments
 (0)