Skip to content

[MOD-17665] Fix sctx double free in _FT.DEBUG FT.HYBRID error paths - #10948

Merged
GuyAv46 merged 1 commit into
masterfrom
guyav-mod-17665-debug-hybrid-sctx
Aug 16, 2026
Merged

GuyAv46 merged 1 commit into
masterfrom
guyav-mod-17665-debug-hybrid-sctx

Conversation

@GuyAv46

@GuyAv46 GuyAv46 commented Aug 16, 2026

Copy link
Copy Markdown
Collaborator

Describe the change

_FT.DEBUG FT.HYBRID double-freed (and used-after-free) the RedisSearchCtx when HybridRequest_Debug_New failed after the hybrid request was built: the parse- and pipeline-build-failure paths free the sctx through the request (HybridRequest_Free frees hreq->sctx), and the handler then freed the same pointer again on the NULL return, guided by a comment that wrongly claimed the inner call "doesn't free it on error".

The ownership contract is now uniform — HybridRequest_Debug_New consumes sctx on every path: the one failure that precedes the container (invalid DEBUG_PARAMS_COUNT) frees it directly, the others free it through the request, and on success the request owns it. The handler's NULL branch only replies.

Reachability is gated (admin _FT.DEBUG, enable-debug-command, single shard), so this is not hit by production deployments with default config — master-only fix, no backports planned.

Adds the missing regression test: a malformed SEARCH expression with a valid DEBUG_PARAMS_COUNT is the only error shape that reaches the buggy path (all existing error tests fail either before the container exists or after Debug_New succeeded). Deterministic; crashes pre-fix under ASAN.

Which issues this PR fixes

MOD-17665

Main objects this PR modified

  • HybridRequest_Debug_New — consumes sctx on every path (contract documented)
  • DEBUG_hybridCommandHandler — no longer frees sctx on the NULL return

Mark if applicable

  • This PR introduces API changes
  • This PR introduces serialization changes

Release notes

  • This PR requires release notes
  • This PR does not require release notes

HybridRequest_Debug_New freed the sctx through the hybrid request on its
parse- and pipeline-build-failure paths (HybridRequest_Free frees
hreq->sctx), yet the handler freed the same pointer again on the NULL
return — a double free reachable with a malformed hybrid query and a valid
DEBUG_PARAMS_COUNT under enable-debug-command. The comment claiming the
inner call "doesn't free it on error" was wrong.

The contract is now uniform: HybridRequest_Debug_New consumes sctx on every
path — the one pre-container failure (invalid DEBUG_PARAMS_COUNT) frees it
directly, the rest free it through the request — and the handler stops
freeing on NULL.

Fixes MOD-17665.

Co-Authored-By: Claude Fable 5 <[email protected]>
@GuyAv46
GuyAv46 requested a review from nafraf August 16, 2026 15:37
@GuyAv46
GuyAv46 enabled auto-merge August 16, 2026 15:37
@GuyAv46
GuyAv46 requested a review from lerman25 August 16, 2026 15:42
@codecov

codecov Bot commented Aug 16, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.19%. Comparing base (2581bdd) to head (c3bb07b).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #10948      +/-   ##
==========================================
- Coverage   83.16%   82.19%   -0.97%     
==========================================
  Files         611      635      +24     
  Lines       81150    82285    +1135     
  Branches    36388    37497    +1109     
==========================================
+ Hits        67486    67637     +151     
- Misses      13317    14301     +984     
  Partials      347      347              
Flag Coverage Δ
flow 84.35% <100.00%> (-0.06%) ⬇️
unit 55.75% <0.00%> (-0.61%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sonarqubecloud

Copy link
Copy Markdown

@GuyAv46
GuyAv46 added this pull request to the merge queue Aug 16, 2026
Merged via the queue into master with commit 63e8ca2 Aug 16, 2026
59 checks passed
@GuyAv46
GuyAv46 deleted the guyav-mod-17665-debug-hybrid-sctx branch August 16, 2026 17:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants