Skip to content

Commit 3b3004d

Browse files
Wenfeng LiuFelipe Zimmerle
Wenfeng Liu
authored and
Felipe Zimmerle
committed
Correct the usage of modsecurity::Phases::NUMBER_OF_PHASES
1 parent ce3abf2 commit 3b3004d

File tree

4 files changed

+10
-17
lines changed

4 files changed

+10
-17
lines changed

headers/modsecurity/rules_properties.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ class RulesProperties {
415415
to->m_responseBodyTypeToBeInspected.m_set = true;
416416
}
417417

418-
for (int i = 0; i <= modsecurity::Phases::NUMBER_OF_PHASES; i++) {
418+
for (int i = 0; i < modsecurity::Phases::NUMBER_OF_PHASES; i++) {
419419
std::vector<actions::Action *> *actions_from = \
420420
from->m_defaultActions+i;
421421
std::vector<actions::Action *> *actions_to = to->m_defaultActions+i;
@@ -535,8 +535,8 @@ class RulesProperties {
535535
ConfigString m_uploadTmpDirectory;
536536
ConfigString m_secArgumentSeparator;
537537
ConfigString m_secWebAppId;
538-
std::vector<actions::Action *> m_defaultActions[8];
539-
std::vector<modsecurity::Rule *> m_rules[8];
538+
std::vector<actions::Action *> m_defaultActions[modsecurity::Phases::NUMBER_OF_PHASES];
539+
std::vector<modsecurity::Rule *> m_rules[modsecurity::Phases::NUMBER_OF_PHASES];
540540
ConfigUnicodeMap m_unicodeMapTable;
541541
};
542542

src/actions/phase.cc

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ bool Phase::init(std::string *error) {
5151
} else if (m_phase == 5) {
5252
m_phase = modsecurity::Phases::LoggingPhase;
5353
m_secRulesPhase = 5;
54+
} else {
55+
error->assign("Unknown phase: " + m_parser_payload);
56+
return false;
5457
}
5558
} catch (...) {
5659
if (a == "request") {
@@ -64,16 +67,6 @@ bool Phase::init(std::string *error) {
6467
m_secRulesPhase = 5;
6568
}
6669
}
67-
if (m_phase == -1) {
68-
error->assign("Not able to associate the given rule to any phase: " + \
69-
m_parser_payload);
70-
return false;
71-
}
72-
73-
if (m_phase > modsecurity::Phases::NUMBER_OF_PHASES) {
74-
error->assign("Unknown phase: " + std::to_string(m_phase));
75-
return false;
76-
}
7770

7871
return true;
7972
}

src/parser/driver.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ int Driver::addSecMarker(std::string marker) {
5252

5353

5454
int Driver::addSecAction(Rule *rule) {
55-
if (rule->m_phase > modsecurity::Phases::NUMBER_OF_PHASES) {
55+
if (rule->m_phase >= modsecurity::Phases::NUMBER_OF_PHASES) {
5656
m_parserError << "Unknown phase: " << std::to_string(rule->m_phase);
5757
m_parserError << std::endl;
5858
return false;
@@ -71,7 +71,7 @@ int Driver::addSecRuleScript(RuleScript *rule) {
7171

7272

7373
int Driver::addSecRule(Rule *rule) {
74-
if (rule->m_phase > modsecurity::Phases::NUMBER_OF_PHASES) {
74+
if (rule->m_phase >= modsecurity::Phases::NUMBER_OF_PHASES) {
7575
m_parserError << "Unknown phase: " << std::to_string(rule->m_phase);
7676
m_parserError << std::endl;
7777
return false;

src/rules.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ std::string Rules::getParserError() {
152152

153153

154154
int Rules::evaluate(int phase, Transaction *t) {
155-
if (phase > modsecurity::Phases::NUMBER_OF_PHASES) {
155+
if (phase >= modsecurity::Phases::NUMBER_OF_PHASES) {
156156
return 0;
157157
}
158158

@@ -293,7 +293,7 @@ void Rules::debug(int level, const std::string &id,
293293

294294
void Rules::dump() {
295295
std::cout << "Rules: " << std::endl;
296-
for (int i = 0; i <= modsecurity::Phases::NUMBER_OF_PHASES; i++) {
296+
for (int i = 0; i < modsecurity::Phases::NUMBER_OF_PHASES; i++) {
297297
std::vector<Rule *> rules = m_rules[i];
298298
std::cout << "Phase: " << std::to_string(i);
299299
std::cout << " (" << std::to_string(rules.size());

0 commit comments

Comments
 (0)