Skip to content

Commit a4813b8

Browse files
stevendoreFelipe Zimmerle
authored andcommitted
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 1aa007e commit a4813b8

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
@@ -431,34 +431,36 @@ class RulesProperties {
431431
std::vector<modsecurity::Rule *> *to,
432432
std::ostringstream *err) {
433433
int amount_of_rules = 0;
434+
// TODO: std::vector could be replaced with something more efficient.
435+
std::vector<int64_t> v;
434436
for (int i = 0; i < modsecurity::Phases::NUMBER_OF_PHASES; i++) {
435437
std::vector<modsecurity::Rule *> *rules_to = to+i;
436-
std::vector<modsecurity::Rule *> *rules_from = from+i;
437-
// FIXME: std::vector could be replaced with something more efficient.
438-
std::vector<int64_t> v;
439438
v.reserve(rules_to->size());
440439
for (size_t z = 0; z < rules_to->size(); z++) {
441440
Rule *rule_ckc = rules_to->at(z);
442-
if (rule_ckc->m_secMarker == false) {
441+
if (rule_ckc->m_secMarker == true) {
443442
continue;
444443
}
445444
v.push_back(rule_ckc->m_ruleId);
446445
}
447-
std::sort(v.begin(), v.end());
446+
}
447+
std::sort (v.begin(), v.end());
448448

449+
for (int i = 0; i < modsecurity::Phases::NUMBER_OF_PHASES; i++) {
450+
std::vector<modsecurity::Rule *> *rules_from = from+i;
451+
std::vector<modsecurity::Rule *> *rules_to = to+i;
449452
for (size_t j = 0; j < rules_from->size(); j++) {
450453
Rule *rule = rules_from->at(j);
451454
if (std::binary_search(v.begin(), v.end(), rule->m_ruleId)) {
452455
if (err != NULL) {
453-
*err << "Rule id: " \
454-
<< std::to_string(rule->m_ruleId) \
456+
*err << "Rule id: " << std::to_string(rule->m_ruleId) \
455457
<< " is duplicated" << std::endl;
456458
}
457459
return -1;
458460
}
459461
amount_of_rules++;
460-
rules_to->push_back(rule);
461462
rule->refCountIncrease();
463+
rules_to->push_back(rule);
462464
}
463465
}
464466
return amount_of_rules;

0 commit comments

Comments
 (0)