Skip to content

ffi: fix use-after-free in PrepareFunction - #66368

Open
trivikr wants to merge 1 commit into
nodejs:mainfrom
trivikr:ffi-segfault-sig-getter-close
Open

trivikr wants to merge 1 commit into
nodejs:mainfrom
trivikr:ffi-segfault-sig-getter-close

Conversation

@trivikr

@trivikr trivikr commented Sep 28, 2026

Copy link
Copy Markdown
Member

Fixes: #66367

PrepareFunction() looked up the function cache before parsing the signature. Parsing can run user getters, and a getter that calls lib.close() clears the cache, which invalidates the iterator. For a function that was already cached, reading it afterwards used freed memory and crashed the process.

Look up the cache after the signature is parsed. If the library was closed during parsing, ResolveSymbol() now throws
ERR_FFI_LIBRARY_CLOSED.


Assisted-by: claude:opus-5.5

PrepareFunction() looked up the function cache before parsing the
signature. Parsing can run user getters, and a getter that calls
lib.close() clears the cache, which invalidates the iterator. For a
function that was already cached, reading it afterwards used freed
memory and crashed the process.

Look up the cache after the signature is parsed. If the library was
closed during parsing, ResolveSymbol() now throws
ERR_FFI_LIBRARY_CLOSED.

Signed-off-by: Trivikram Kamat <16024985+trivikr@users.noreply.github.com>
Assisted-by: claude:opus-5.5
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/ffi

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. labels Sep 28, 2026
@daeyeon daeyeon added author ready PRs with CI started, the required approvals, and no outstanding review comments. request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. ffi Issues and PRs related to experimental Foreign Function Interface support. labels Sep 28, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Sep 28, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@codecov

codecov Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.37%. Comparing base (75e4bbe) to head (8d87696).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #66368   +/-   ##
=======================================
  Coverage   90.36%   90.37%           
=======================================
  Files         792      792           
  Lines      275398   275398           
  Branches    52776    52777    +1     
=======================================
+ Hits       248877   248891   +14     
+ Misses      16937    16932    -5     
+ Partials     9584     9575    -9     
Files with missing lines Coverage Δ
src/node_ffi.cc 72.40% <100.00%> (ø)

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

@panva panva added the resume-ci Add this label to resume the latest eligible Jenkins CI run on a PR with an approving review. label Sep 28, 2026
@github-actions github-actions Bot removed the resume-ci Add this label to resume the latest eligible Jenkins CI run on a PR with an approving review. label Sep 28, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@addaleax addaleax added the commit-queue PRs queued for automated landing through the Commit Queue. label Sep 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs with CI started, the required approvals, and no outstanding review comments. c++ Issues and PRs that require attention from people who are familiar with C++. commit-queue PRs queued for automated landing through the Commit Queue. ffi Issues and PRs related to experimental Foreign Function Interface support. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ffi: segfault when a signature getter closes the library in getFunction()

7 participants