Skip to content

fix(antlr4): fix rule index UAF and chain update - #140

Merged
zhouyujt merged 1 commit into
stone-rhino:mainfrom
IYanyaning:fix/rule-index-uaf-and-chain-update
Jan 29, 2026
Merged

fix(antlr4): fix rule index UAF and chain update#140
zhouyujt merged 1 commit into
stone-rhino:mainfrom
IYanyaning:fix/rule-index-uaf-and-chain-update

Conversation

@IYanyaning

Copy link
Copy Markdown
Collaborator
  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 #139

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
zhouyujt self-requested a review January 29, 2026 02:59

@zhouyujt zhouyujt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job!

@zhouyujt
zhouyujt merged commit 5aad3ef into stone-rhino:main Jan 29, 2026
1 check passed
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
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.

[Bug] Potential Segmentation Fault in secRuleRemoveById due to Iterator Invalidation and Incomplete Chain Rule Updates

2 participants