Skip to content

crypto,quic: add NULL checks for OpenSSL allocation functions - #63040

Closed
armorbreak001 wants to merge 2 commits into
nodejs:mainfrom
armorbreak001:fix/crypto-null-checks
Closed

armorbreak001 wants to merge 2 commits into
nodejs:mainfrom
armorbreak001:fix/crypto-null-checks

Conversation

@armorbreak001

@armorbreak001 armorbreak001 commented Apr 29, 2026 •

Copy link
Copy Markdown

Fixes: #62774

This PR adds graceful NULL checks for OpenSSL allocation function return values, replacing CHECK() assertions that would abort the process on allocation failure.

Changes

src/crypto/crypto_aes.cc β€” AES_Cipher()

Replaced CHECK(ctx) with:

if (!ctx) {
  return WebCryptoCipherStatus::FAILED;
}

This matches the pattern already used in AES_CTR_Cipher2() in the same file.

src/crypto/crypto_cipher.cc β€” CipherBase::CommonInit()

Replaced CHECK(ctx_) with:

if (!ctx_) {
  return ThrowCryptoError(env(),
                          mark_pop_error_on_return.peekError(),
                          "Failed to allocate cipher context");
}

This matches the error handling pattern used elsewhere in the same function.

Note on other locations from #62774

  • AES_CTR_Cipher2() β€” Already has a proper if (!ctx) check (line 238)
  • TLSSession::Initialize() β€” Already has a proper if (!ssl) check (line 794)
  • ECKeyExportTraits::DoExport() β€” This function no longer exists in the current codebase; the EC key handling code has been refactored

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/crypto

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. crypto Issues and PRs related to the crypto subsystem. needs-ci PRs that need a full CI run. labels Apr 29, 2026
@armorbreak001
armorbreak001 force-pushed the fix/crypto-null-checks branch from 234ce29 to 78ab09a Compare April 29, 2026 20:59
@armorbreak001 armorbreak001 changed the title crypto: add NULL checks for OpenSSL allocation functions crypto,quic: add NULL checks for OpenSSL allocation functions Apr 29, 2026
@armorbreak001
armorbreak001 force-pushed the fix/crypto-null-checks branch from 78ab09a to cb76fb6 Compare May 16, 2026 01:19
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@codecov

codecov Bot commented May 16, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 5 lines in your changes missing coverage. Please review.
βœ… Project coverage is 90.05%. Comparing base (5d578c5) to head (1fb33d5).
⚠️ Report is 659 commits behind head on main.

Files with missing lines Patch % Lines
src/crypto/crypto_cipher.cc 0.00% 2 Missing and 1 partial ⚠️
src/crypto/crypto_aes.cc 0.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #63040      +/-   ##
==========================================
+ Coverage   89.65%   90.05%   +0.39%     
==========================================
  Files         708      714       +6     
  Lines      220402   225525    +5123     
  Branches    42269    42642     +373     
==========================================
+ Hits       197597   203087    +5490     
+ Misses      14671    14205     -466     
- Partials     8134     8233      +99     
Files with missing lines Coverage Ξ”
src/crypto/crypto_aes.cc 53.63% <0.00%> (-0.19%) ⬇️
src/crypto/crypto_cipher.cc 77.13% <0.00%> (-0.31%) ⬇️

... and 150 files with indirect coverage changes

πŸš€ New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • πŸ“¦ JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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 nodejs#62774

Signed-off-by: armorbreak001 <contact@agentvote.cc>
@armorbreak001
armorbreak001 force-pushed the fix/crypto-null-checks branch from cb76fb6 to 3899839 Compare May 16, 2026 07:07
Signed-off-by: armorbreak001 <contact@agentvote.cc>
@armorbreak001

Copy link
Copy Markdown
Author

Hi @nodejs/crypto team β€” just wanted to follow up on this PR. It adds NULL checks for OpenSSL allocation functions in crypto_aes.cc and crypto_cipher.cc, which could prevent potential crashes on allocation failure.

I understand the team is busy. If there are any changes needed or if this isn't the right approach, I'm happy to adjust. Thanks for your time!

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@jasnell

jasnell commented Jul 6, 2026

Copy link
Copy Markdown
Member

@armorbreak001 ... as a general rule, please do not try to add empty commits to trigger CI. It doesn't work.

@armorbreak001

Copy link
Copy Markdown
Author

@jasnell Understood, my apologies for that. Won't do it again β€” I'll wait for CI to pick up changes naturally. Thanks for the approval and for letting me know.

@jasnell

jasnell commented Aug 8, 2026

Copy link
Copy Markdown
Member

This needs a rebase

@armorbreak001

Copy link
Copy Markdown
Author

Thanks for the heads-up! I checked the latest upstream/main and it looks like these NULL checks have already been applied (both src/crypto/crypto_aes.cc:51 and src/crypto/crypto_cipher.cc:346 now have the proper null guards).

Closing this PR as superseded β€” the fix made it in! πŸŽ‰

@armorbreak001

Copy link
Copy Markdown
Author

Superseded β€” fix already present in main

@armorbreak001
armorbreak001 deleted the fix/crypto-null-checks branch August 8, 2026 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. crypto Issues and PRs related to the crypto subsystem. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

crypto,quic: missing NULL checks for OpenSSL allocation functions

3 participants