From 0aadc1624812313e4d88b2d76989c8c5eeac0ceb Mon Sep 17 00:00:00 2001 From: Christian Kreibich Date: Thu, 14 Nov 2024 16:30:11 -0800 Subject: [PATCH] Use vectors instead of sets in RuleMatcher iterations for canonical ordering We don't need sets for temporary result storage, since we can just iterate in the (reliable) ordering built up by adding to a vector. This fixes a test failure we're seeing on Alpine for the signatures/tcp-end-of-match btest. --- src/RuleMatcher.cc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/RuleMatcher.cc b/src/RuleMatcher.cc index d88168467c1..910b53be284 100644 --- a/src/RuleMatcher.cc +++ b/src/RuleMatcher.cc @@ -658,7 +658,7 @@ RuleMatcher::MIME_Matches* RuleMatcher::Match(RuleFileMagicState* state, const u } // Find rules for which patterns have matched. - set rule_matches; + vector rule_matches; for ( AcceptingMatchSet::const_iterator it = accepted_matches.begin(); it != accepted_matches.end(); ++it ) { auto [aidx, mpos] = *it; @@ -666,10 +666,10 @@ RuleMatcher::MIME_Matches* RuleMatcher::Match(RuleFileMagicState* state, const u Rule* r = Rule::rule_table[aidx - 1]; if ( AllRulePatternsMatched(r, mpos, accepted_matches) ) - rule_matches.insert(r); + rule_matches.emplace_back(r); } - for ( set::const_iterator it = rule_matches.begin(); it != rule_matches.end(); ++it ) { + for ( vector::const_iterator it = rule_matches.begin(); it != rule_matches.end(); ++it ) { Rule* r = *it; for ( const auto& action : r->actions ) { @@ -842,7 +842,7 @@ void RuleMatcher::Match(RuleEndpointState* state, Rule::PatternType type, const // matched patterns per connection (which is a plausible assumption). // Find rules for which patterns have matched. - set> rule_matches; + vector> rule_matches; for ( AcceptingMatchSet::const_iterator it = accepted_matches.begin(); it != accepted_matches.end(); ++it ) { AcceptIdx aidx = it->first; @@ -851,12 +851,12 @@ void RuleMatcher::Match(RuleEndpointState* state, Rule::PatternType type, const Rule* r = Rule::rule_table[aidx - 1]; if ( AllRulePatternsMatched(r, mpos, accepted_matches) ) - rule_matches.insert(make_pair(r, mpos)); + rule_matches.emplace_back(make_pair(r, mpos)); } // Check which of the matching rules really belong to any of our nodes. - for ( set>::const_iterator it = rule_matches.begin(); it != rule_matches.end(); ++it ) { + for ( vector>::const_iterator it = rule_matches.begin(); it != rule_matches.end(); ++it ) { auto [r, match_end_pos] = *it; DBG_LOG(DBG_RULES, "Accepted rule: %s", r->id);