Repository navigation
Conversation
msc_pregcomp_ex registered msc_pcre_cleanup only at the very end, so on the failure paths between the compile and the return (the match context allocation with PCRE2, the pcre_extra allocation with legacy PCRE) the function returned NULL and the compiled pattern was never freed. The cleanup is now registered as soon as the compile succeeds; it already tolerates a NULL match context / pcre_extra. Fixes owasp-modsecurity#2407 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0181jBv5JdNQviwDzfnkf1Gy
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



What
msc_pregcomp_ex(apache2/msc_pcre.c) registers themsc_pcre_cleanuppool cleanup right after the pattern compiles successfully, in both the PCRE2 and the legacy PCRE branch, instead of only at the end of the function.Why
Every failure path between the compile and the return (
pcre2_match_context_createwith PCRE2, thepcre_extraallocation with legacy PCRE) returnedNULLwithout freeing the compiled pattern, as reported in #2407. With the cleanup registered as soon as there is something to release, those paths are covered;msc_pcre_cleanupalready tolerates aNULLmatch context /pcre_extra.Note that in the current code
pcre2_jit_compilefailing does not return early (the result is kept injit_compile_rc), so the window is the allocation failures only. The reordering costs nothing and removes it.Tests
No new test: the leak only shows on an allocation failure. Verified in a Debian bookworm container (apache2 2.4, PCRE2 with JIT) that the branch builds and that the unit tests and
tests/regression/misc/10-pcre.tpass as on untouchedv2/master(the one unit-test failure, anipMatchassertion with--enable-assertions, is pre-existing onv2/master).References
Fixes #2407
🤖 Generated with Claude Code