Skip to content

Comments

crypto: fix handling of null BUF_MEM* in ToV8Value()#61885

Merged
nodejs-github-bot merged 4 commits intonodejs:mainfrom
ndossche:clesss-4
Feb 25, 2026
Merged

crypto: fix handling of null BUF_MEM* in ToV8Value()#61885
nodejs-github-bot merged 4 commits intonodejs:mainfrom
ndossche:clesss-4

Conversation

@ndossche
Copy link
Contributor

The assignment to bptr calls BIO_get_mem_ptr which can fail and leave the bptr as nullptr. This then later causes a null pointer deref.
This is inconsistent with uses of the similar function BIO_get_mem_data that do check its return value, e.g. node::crypto::X509sToArrayOfStrings().
Solve it by checking for a null pointer and handling the Nothing return value at the call sites.

Note: this was found by a static-dynamic analyser I'm developing.

The assignment to `bptr` calls `BIO_get_mem_ptr` which can fail and
leave the `bptr` as nullptr. This then later causes a null pointer
deref.
This is inconsistent with uses of the similar function
`BIO_get_mem_data` that do check its return value, e.g.
`node::crypto::X509sToArrayOfStrings()`.
Solve it by checking for a null pointer and handling the `Nothing`
return value at the call sites.
@nodejs-github-bot
Copy link
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 Feb 19, 2026
@codecov
Copy link

codecov bot commented Feb 19, 2026

Codecov Report

❌ Patch coverage is 0% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.77%. Comparing base (4f13746) to head (44906b0).
⚠️ Report is 49 commits behind head on main.

Files with missing lines Patch % Lines
src/crypto/crypto_keys.cc 0.00% 4 Missing and 2 partials ⚠️
src/crypto/crypto_x509.cc 0.00% 3 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #61885      +/-   ##
==========================================
+ Coverage   89.72%   89.77%   +0.04%     
==========================================
  Files         675      674       -1     
  Lines      204806   205624     +818     
  Branches    39355    39425      +70     
==========================================
+ Hits       183761   184596     +835     
+ Misses      13330    13271      -59     
- Partials     7715     7757      +42     
Files with missing lines Coverage Δ
src/crypto/crypto_keys.cc 73.75% <0.00%> (-0.32%) ⬇️
src/crypto/crypto_x509.cc 72.44% <0.00%> (-0.64%) ⬇️

... and 130 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.

Copy link
Member

@addaleax addaleax left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The BUF_MEM* changes are fundamentally reasonable, although they are a strong argument why they really should not be using implicit casting operators. However, both looking at the OpenSSL source code and documentation, there seems to be no indication that these would be able to fail.

The ToV8Value() changes are definitely incorrect; if ToV8Value() does not already schedule an exception to be thrown when returning an empty value, that's a bug in ToV8Value() itself.

@ndossche
Copy link
Contributor Author

However, both looking at the OpenSSL source code and documentation, there seems to be no indication that these would be able to fail.

I suppose it depends. The OpenSSL documentation is incomplete as usual and doesn't indicate what the return value means. Looking at the source, a registered callback could still trigger a failure. LibreSSL puts the failure more explicitly: https://man.openbsd.org/BIO_s_mem.3 where it indicates "return 1 on success or a value less than or equal to 0 if an error occurred."

@addaleax
Copy link
Member

@ndossche Yeah, and like I said, it's a fundamentally reasonable change. My "request changes" bit primarily refers to the ToV8Value() error handling.

@addaleax addaleax added request-ci Add this label to start a Jenkins CI on a PR. author ready PRs that have at least one approval, no pending requests for changes, and a CI started. labels Feb 25, 2026
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Feb 25, 2026
@nodejs-github-bot
Copy link
Collaborator

@addaleax addaleax added commit-queue Add this label to land a pull request using GitHub Actions. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. labels Feb 25, 2026
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Feb 25, 2026
@nodejs-github-bot nodejs-github-bot merged commit 488a854 into nodejs:main Feb 25, 2026
74 checks passed
@nodejs-github-bot
Copy link
Collaborator

Landed in 488a854

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs that have at least one approval, no pending requests for changes, and a CI started. c++ Issues and PRs that require attention from people who are familiar with C++. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. 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.

4 participants