Skip to content

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

Open
Flarna wants to merge 2 commits 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 2 commits 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 83.33333% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 89.65%. Comparing base (afc30b7) to head (2eef7e7).
⚠️ Report is 10 commits behind head on main.

Files with missing lines Patch % Lines
src/node_http_parser.cc 80.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #62095      +/-   ##
==========================================
+ Coverage   89.64%   89.65%   +0.01%     
==========================================
  Files         676      676              
  Lines      206326   206336      +10     
  Branches    39528    39527       -1     
==========================================
+ Hits       184960   185000      +40     
+ Misses      13476    13465      -11     
+ Partials     7890     7871      -19     
Files with missing lines Coverage Δ
lib/_http_common.js 100.00% <100.00%> (ø)
src/node_http_parser.cc 84.71% <80.00%> (-0.02%) ⬇️

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

@addaleax addaleax added the commit-queue Add this label to land a pull request using GitHub Actions. label Mar 5, 2026
@Flarna Flarna removed the commit-queue Add this label to land a pull request using GitHub Actions. label Mar 5, 2026
@Flarna Flarna added the commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. label Mar 5, 2026
@Flarna Flarna added the request-ci Add this label to start a Jenkins CI on a PR. label Mar 5, 2026
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. 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. request-ci Add this label to start a Jenkins CI on a PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants