Skip to content

Fix use-after-free when generated C output cannot be written - #334

Merged
trufae merged 1 commit into
masterfrom
fix-cgen-drain-error
Oct 30, 2026
Merged

trufae merged 1 commit into
masterfrom
fix-cgen-drain-error

Conversation

@trufae

@trufae trufae commented Oct 30, 2026

Copy link
Copy Markdown
Collaborator

When recursive database generation cannot open or write its generated C file, dothec() jumps to cleanup with a dangling sb: strbuf_drain() has already freed it. strbuf_free(sb) then reads freed memory and may crash.

Clear sb immediately after draining it. This also covers an empty drain and a short write. Add a regression case to the existing recursive CLI test by making the output C path a directory.

Validation: reproduced the pre-fix heap-use-after-free with ASan at strbuf_free() (src/strbuf.c:79), called from dothec(). The same reproducer and test/recursive.sh pass after the fix with ASan/UBSan and USE_MMAN=0.

Found while investigating the intermittent Windows build failure in radareorg/radare2#27270. This fixes a confirmed error-path bug; it is not yet established as the cause of that particular CI failure.

@trufae
trufae merged commit 7eb5e54 into master Oct 30, 2026
15 checks passed
@trufae
trufae deleted the fix-cgen-drain-error branch October 30, 2026 06:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant