Skip to content

http: fix use-after-free when freeParser is called during llhttp_execute#62095

Open
Flarna wants to merge 1 commit intonodejs:mainfrom
Flarna:http_parser_use_after_free
Open

http: fix use-after-free when freeParser is called during llhttp_execute#62095
Flarna wants to merge 1 commit intonodejs:mainfrom
Flarna:http_parser_use_after_free

Conversation

@Flarna
Copy link
Member

@Flarna Flarna commented Mar 3, 2026

When pipelined requests arrive in one TCP segment, llhttp_execute() parses them all in a single call. If a synchronous 'close' event handler invokes freeParser() mid-execution, cleanParser() nulls out parser state while llhttp_execute() is still on the stack, crashing on the next callback.

Add an is_being_freed_ flag that freeParser() sets via parser.markFreed() before cleaning state. Proxy::Raw checks the flag before every callback and returns HPE_USER to abort execution early if set.

Fix/test was created using AI support.

Refs: #61995 (comment)

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/http
  • @nodejs/net

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. http Issues or PRs related to the http subsystem. http_parser Issues and PRs related to the HTTP Parser dependency or the http_parser binding. needs-ci PRs that need a full CI run. labels Mar 3, 2026
@Flarna Flarna force-pushed the http_parser_use_after_free branch from 9943149 to ff06bb7 Compare March 3, 2026 23:15
@Flarna Flarna changed the title http: fix use-after-free when freeParser() is called during llhttp_execute() http: fix use-after-free when freeParser is called during llhttp_execute Mar 3, 2026
When pipelined requests arrive in one TCP segment, llhttp_execute()
parses them all in a single call. If a synchronous 'close' event
handler invokes freeParser() mid-execution, cleanParser() nulls out
parser state while llhttp_execute() is still on the stack, crashing on
 the next callback.

Add an is_being_freed_ flag that freeParser() sets via
parser.markFreed() before cleaning state. Proxy::Raw checks the flag
before every callback and returns HPE_USER to abort execution early if
set.
@Flarna Flarna force-pushed the http_parser_use_after_free branch from ff06bb7 to d2ea166 Compare March 3, 2026 23:21
@codecov
Copy link

codecov bot commented Mar 4, 2026

Codecov Report

❌ Patch coverage is 81.81818% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.65%. Comparing base (afc30b7) to head (d2ea166).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
src/node_http_parser.cc 80.00% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #62095      +/-   ##
==========================================
+ Coverage   89.64%   89.65%   +0.01%     
==========================================
  Files         676      676              
  Lines      206326   206338      +12     
  Branches    39528    39524       -4     
==========================================
+ Hits       184960   184996      +36     
+ Misses      13476    13468       -8     
+ Partials     7890     7874      -16     
Files with missing lines Coverage Δ
lib/_http_common.js 100.00% <100.00%> (ø)
src/node_http_parser.cc 84.68% <80.00%> (-0.05%) ⬇️

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

@Flarna Flarna added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Mar 4, 2026
Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

@Flarna Flarna added the request-ci Add this label to start a Jenkins CI on a PR. label Mar 4, 2026
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Mar 4, 2026
@nodejs-github-bot
Copy link
Collaborator

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++. http_parser Issues and PRs related to the HTTP Parser dependency or the http_parser binding. http Issues or PRs related to the http 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