Skip to content

Commit 889186d

Browse files
committed
Fix RulesProperties::appendRules()
RulesProperties::appendRules() was not checking for duplicate IDs as well as throwing an error if there were secMarkers in more than one file (when calling any combination of rules->load(), rules->loadFromUri() or rules->loadRemote() more than once). To fix the secMarker issue, the if statement on rules_properties.h:441 just needed to be negated. This function also doesn't accurately check for duplicate IDs. the check can be circumvented by putting the rule in a different phase. To fix this the ruleId list (v) had to be populated completely before checking against the other list.
1 parent c2bc695 commit 889186d

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

headers/modsecurity/rules_properties.h

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -430,34 +430,36 @@ class RulesProperties {
430430
std::vector<modsecurity::Rule *> *to,
431431
std::ostringstream *err) {
432432
int amount_of_rules = 0;
433+
// TODO: std::vector could be replaced with something more efficient.
434+
std::vector<int64_t> v;
433435
for (int i = 0; i < modsecurity::Phases::NUMBER_OF_PHASES; i++) {
434436
std::vector<modsecurity::Rule *> *rules_to = to+i;
435-
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;
438437
v.reserve(rules_to->size());
439438
for (size_t z = 0; z < rules_to->size(); z++) {
440439
Rule *rule_ckc = rules_to->at(z);
441-
if (rule_ckc->m_secMarker == false) {
440+
if (rule_ckc->m_secMarker == true) {
442441
continue;
443442
}
444443
v.push_back(rule_ckc->m_ruleId);
445444
}
446-
std::sort (v.begin(), v.end());
445+
}
446+
std::sort (v.begin(), v.end());
447447

448+
for (int i = 0; i < modsecurity::Phases::NUMBER_OF_PHASES; i++) {
449+
std::vector<modsecurity::Rule *> *rules_from = from+i;
450+
std::vector<modsecurity::Rule *> *rules_to = to+i;
448451
for (size_t j = 0; j < rules_from->size(); j++) {
449452
Rule *rule = rules_from->at(j);
450453
if (std::binary_search (v.begin(), v.end(), rule->m_ruleId)) {
451454
if (err != NULL) {
452-
*err << "Rule id: " \
453-
<< std::to_string(rule->m_ruleId) \
455+
*err << "Rule id: " << std::to_string(rule->m_ruleId) \
454456
<< " is duplicated" << std::endl;
455457
}
456458
return -1;
457459
}
458460
amount_of_rules++;
459-
rules_to->push_back(rule);
460461
rule->refCountIncrease();
462+
rules_to->push_back(rule);
461463
}
462464
}
463465
return amount_of_rules;

0 commit comments

Comments
 (0)