fix(antlr4): fix rule index UAF and chain update - #140
Merged
zhouyujt merged 1 commit intoJan 29, 2026
Conversation
1. Fixed a Use-After-Free (UAF) in `secRuleRemoveById`: Previously, the code accessed the `rules_index_id_` iterator after it was invalidated by `clearRuleIdIndex()`. Now, it is guaranteed that the index data used when rules are erased is a local stack variable cached before index cleanup. 2. Fixed a dangling pointer caused by `std::vector` relocation: Because rules are stored by value, deleting an element causes subsequent elements to be offset in memory. - Adjusted `updateChainRule` to start from the correct affected index. - Replaced shallow chain updates with iterative depth-first traversal to ensure that all nested 'chain_rule' nodes (top_rule_) are recalibrated to the new memory address. Fixes stone-rhino#139
zhouyujt
self-requested a review
January 29, 2026 02:59
zhouyujt
approved these changes
Jan 29, 2026
hawkeyetw
pushed a commit
to hawkeyetw/wge
that referenced
this pull request
Apr 30, 2026
1. Fixed a Use-After-Free (UAF) in `secRuleRemoveById`: Previously, the code accessed the `rules_index_id_` iterator after it was invalidated by `clearRuleIdIndex()`. Now, it is guaranteed that the index data used when rules are erased is a local stack variable cached before index cleanup. 2. Fixed a dangling pointer caused by `std::vector` relocation: Because rules are stored by value, deleting an element causes subsequent elements to be offset in memory. - Adjusted `updateChainRule` to start from the correct affected index. - Replaced shallow chain updates with iterative depth-first traversal to ensure that all nested 'chain_rule' nodes (top_rule_) are recalibrated to the new memory address. Fixes stone-rhino#139
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.
secRuleRemoveById:Previously, the code accessed the
rules_index_id_iterator after it was invalidated byclearRuleIdIndex().Now, it is guaranteed that the index data used when rules are erased is a local stack variable cached before index cleanup.
std::vectorrelocation:Because rules are stored by value, deleting an element causes subsequent elements to be offset in memory.
updateChainRuleto start from the correct affected index.Fixes #139