Skip to content

Commit 65aa7ae

Browse files
author
Felipe Zimmerle
committed
Improves the performance while loading the rules
Based on the findings listed on #1735
1 parent 4e3a1f7 commit 65aa7ae

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

CHANGES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
v3.0.3 - YYYY-MMM-DD (to be released)
22
-------------------------------------
33

4+
- Improves the performance while loading the rules
5+
[Issue #1735 - @zimmerle, @p0pr0ck5, @victorhora]
46
- Allow empty strings to be evaluated by regex::searchAll
57
[Issue #1799, #1785 - @victorhora, @XuanHuyDuong, @zimmerle]
68
- Adds basic pkg-config info

headers/modsecurity/rules_properties.h

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -433,20 +433,27 @@ class RulesProperties {
433433
for (int i = 0; i < modsecurity::Phases::NUMBER_OF_PHASES; i++) {
434434
std::vector<modsecurity::Rule *> *rules_to = to+i;
435435
std::vector<modsecurity::Rule *> *rules_from = from+i;
436+
// TODO: std::vector could be replaced with something more efficient.
437+
std::vector<int64_t> v;
438+
v.reserve(rules_to->size());
439+
for (size_t z = 0; z < rules_to->size(); z++) {
440+
Rule *rule_ckc = rules_to->at(z);
441+
if (rule_ckc->m_secMarker == false) {
442+
continue;
443+
}
444+
v.push_back(rule_ckc->m_ruleId);
445+
}
446+
std::sort (v.begin(), v.end());
447+
436448
for (size_t j = 0; j < rules_from->size(); j++) {
437449
Rule *rule = rules_from->at(j);
438-
for (size_t z = 0; z < rules_to->size(); z++) {
439-
Rule *rule_ckc = rules_to->at(z);
440-
if (rule_ckc->m_ruleId == rule->m_ruleId &&
441-
rule_ckc->m_secMarker == false &&
442-
rule->m_secMarker == false) {
443-
if (err != NULL) {
444-
*err << "Rule id: " \
445-
<< std::to_string(rule->m_ruleId) \
446-
<< " is duplicated" << std::endl;
447-
}
448-
return -1;
450+
if (std::binary_search (v.begin(), v.end(), rule->m_ruleId)) {
451+
if (err != NULL) {
452+
*err << "Rule id: " \
453+
<< std::to_string(rule->m_ruleId) \
454+
<< " is duplicated" << std::endl;
449455
}
456+
return -1;
450457
}
451458
amount_of_rules++;
452459
rules_to->push_back(rule);

0 commit comments

Comments
 (0)