Refactoring the cleaning of MATCHED_VAR* variables #3422
Merged
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
This PR changes the code behavior: now the engine cleans the
MATCHED_VAR*
variables after chained and non-chained rules too.With current behavior if a rule is not chained then
MATCHED_VAR*
variables kept their values.Changes:
cleanMatchedVars()
method fromRuleWithOperator
class toRuleSet
RuleWithOperator
represents aSecRule
object, which can be a chained or non-chained rule; it's important thatSecRule
(in this context) has a variable and an operator at least (SecAction
does not have these)RuleSet
is a container which holdsSecRule
andSecAction
objectsevaluate()
method is called from the transaction's phase, thenRuleSet
evaluates all rules and actions in a loopcleanMatchedVars()
was a part ofRuleWithOperator
(which is aSecRule
), then it was possible to call that only from that classRulesSet
object evaluates the rules of phases, now we can call it after allevaluate()
call - and the condition fits that it cleans theMATCHED_VAR*
variables after all single rule and after all last part of chained rulewhy
The issue #3382 describes the problem: if a non-chained rule evaluated, and the rule filled the
MATCHED_VAR*
variables, then those values remained after the ending of evaluation. Then if a next rule used any ofMATCHED_VAR*
, it found those values and led a false match.other notes
There was a try before this, see #3418. There - as I wrote above - wasn't clean how the solution solves the issue exactly and was a suggestion we should clean these variables before the rule's evaluation. It was not possible, because the
cleanMatchedVars()
was a part of the one rule's method.references
Closes #3382.