crypto: replace CHECK with NULL checks for EVP_CIPHER_CTX_new allocations#62816
Open
Jah-yee wants to merge 1 commit intonodejs:mainfrom
Open
crypto: replace CHECK with NULL checks for EVP_CIPHER_CTX_new allocations#62816Jah-yee wants to merge 1 commit intonodejs:mainfrom
Jah-yee wants to merge 1 commit intonodejs:mainfrom
Conversation
…ions 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: nodejs#62774
Collaborator
|
Review requested:
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #62816 +/- ##
==========================================
- Coverage 89.69% 89.68% -0.02%
==========================================
Files 706 706
Lines 218222 218225 +3
Branches 41768 41766 -2
==========================================
- Hits 195731 195709 -22
- Misses 14411 14417 +6
- Partials 8080 8099 +19
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Good day
This PR addresses issue #62774, which identifies missing NULL checks for OpenSSL allocation functions in the Node.js crypto module.
Changes
src/crypto/crypto_aes.cc
In the `AES_Cipher` function, replaced `CHECK(ctx)` with a proper NULL check:
```cpp
auto ctx = CipherCtxPointer::New();
if (!ctx) {
return WebCryptoCipherStatus::FAILED;
}
```
src/crypto/crypto_cipher.cc
In the `CipherBase::CommonInit` function, replaced `CHECK(ctx_)` with a proper error throw:
```cpp
ctx_ = CipherCtxPointer::New();
if (!ctx_) {
return ThrowCryptoError(env(),
mark_pop_error_on_return.peekError(),
"EVP_CIPHER_CTX_new");
}
```
Why These Changes
The `CHECK()` macro is an assertion that calls `abort()` on failure. This is not appropriate for recoverable allocation failures (such as out-of-memory conditions). The new code:
This makes the code consistent with the rest of the codebase and handles allocation failures gracefully instead of crashing.
Thank you for your attention. If there are any issues or suggestions, please leave a comment and I will address them promptly.
Warmly,
RoomWithOutRoof