Skip to content

Commit 6c87472

Browse files
committed
Moves default actions to be part of the rules
1 parent 2e2417f commit 6c87472

File tree

8 files changed

+26
-29
lines changed

8 files changed

+26
-29
lines changed

CHANGES

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

4+
- Using std::shared_ptr instead of generates its own references counters
5+
for Rules and related.
6+
[@zimmerle]
7+
- Better handle shared_pointers on messages aiming for better performance.
8+
[@zimmerle]
9+
- Better handle memory usage on transformations aiming for better
10+
performance.
11+
[@zimmerle]
12+
- Coding refactoring on the Rule class. The Rule class is now refactored
13+
into RuleWithOperator, RuleWithActions, and RuleUnconditional.
414
- EXPERIMENTAL: Add new transformation call phpArgsNames
515
[Issue #2387 - @marshal09]
616

headers/modsecurity/rules.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ class Rules {
8484
std::shared_ptr<Rule> operator[](int index) const { return m_rules[index]; }
8585
std::shared_ptr<Rule> at(int index) const { return m_rules[index]; }
8686

87+
std::vector<std::shared_ptr<actions::Action> > m_defaultActions;
88+
8789
std::vector<std::shared_ptr<Rule> > m_rules;
8890
};
8991

headers/modsecurity/rules_set_properties.h

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -201,16 +201,6 @@ class RulesSetProperties {
201201
RulesSetProperties &operator =(const RulesSetProperties &r) = delete;
202202

203203
~RulesSetProperties() {
204-
int i = 0;
205-
206-
for (i = 0; i < modsecurity::Phases::NUMBER_OF_PHASES; i++) {
207-
std::vector<std::shared_ptr<actions::Action> > *tmp = \
208-
&m_defaultActions[i];
209-
while (tmp->empty() == false) {
210-
tmp->pop_back();
211-
}
212-
}
213-
214204
delete m_debugLog;
215205
delete m_auditLog;
216206
}
@@ -410,16 +400,6 @@ class RulesSetProperties {
410400
to->m_responseBodyTypeToBeInspected.m_set = true;
411401
}
412402

413-
for (int i = 0; i < modsecurity::Phases::NUMBER_OF_PHASES; i++) {
414-
std::vector<std::shared_ptr<actions::Action> > *actions_from = \
415-
&from->m_defaultActions[i];
416-
std::vector<std::shared_ptr<actions::Action> > *actions_to = \
417-
&to->m_defaultActions[i];
418-
for (size_t j = 0; j < actions_from->size(); j++) {
419-
actions_to->push_back(actions_from->at(j));
420-
}
421-
}
422-
423403
if (to->m_auditLog) {
424404
std::string error;
425405
to->m_auditLog->merge(from->m_auditLog, &error);
@@ -481,8 +461,6 @@ class RulesSetProperties {
481461
ConfigString m_uploadTmpDirectory;
482462
ConfigString m_secArgumentSeparator;
483463
ConfigString m_secWebAppId;
484-
std::vector<std::shared_ptr<actions::Action> > \
485-
m_defaultActions[modsecurity::Phases::NUMBER_OF_PHASES];
486464
ConfigUnicodeMap m_unicodeMapTable;
487465
};
488466

src/actions/block.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ bool Block::evaluate(RuleWithActions *rule, Transaction *transaction,
3333
std::shared_ptr<RuleMessage> rm) {
3434
ms_dbg_a(transaction, 8, "Marking request as disruptive.");
3535

36-
for (auto &a : transaction->m_rules->m_defaultActions[rule->getPhase()]) {
36+
for (auto &a : transaction->m_rules->m_rulesSetPhases[rule->getPhase()]->m_defaultActions) {
3737
if (a->isDisruptive() == false) {
3838
continue;
3939
}

src/parser/seclang-parser.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2437,7 +2437,7 @@ namespace yy {
24372437
YYERROR;
24382438
}
24392439

2440-
if (!driver.m_defaultActions[definedPhase].empty()) {
2440+
if (!driver.m_rulesSetPhases[definedPhase]->m_defaultActions.empty()) {
24412441
std::stringstream ss;
24422442
ss << "SecDefaultActions can only be placed once per phase and configuration context. Phase ";
24432443
ss << secRuleDefinedPhase;
@@ -2447,7 +2447,7 @@ namespace yy {
24472447
}
24482448

24492449
for (actions::Action *a : checkedActions) {
2450-
driver.m_defaultActions[definedPhase].push_back(
2450+
driver.m_rulesSetPhases[definedPhase]->m_defaultActions.push_back(
24512451
std::unique_ptr<actions::Action>(a));
24522452
}
24532453

src/parser/seclang-parser.yy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,7 +1209,7 @@ expression:
12091209
YYERROR;
12101210
}
12111211

1212-
if (!driver.m_defaultActions[definedPhase].empty()) {
1212+
if (!driver.m_rulesSetPhases[definedPhase]->m_defaultActions.empty()) {
12131213
std::stringstream ss;
12141214
ss << "SecDefaultActions can only be placed once per phase and configuration context. Phase ";
12151215
ss << secRuleDefinedPhase;
@@ -1219,7 +1219,7 @@ expression:
12191219
}
12201220

12211221
for (actions::Action *a : checkedActions) {
1222-
driver.m_defaultActions[definedPhase].push_back(
1222+
driver.m_rulesSetPhases[definedPhase]->m_defaultActions.push_back(
12231223
std::unique_ptr<actions::Action>(a));
12241224
}
12251225

src/rule_with_actions.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ void RuleWithActions::executeActionsAfterFullMatch(Transaction *trans,
222222
bool containsBlock, std::shared_ptr<RuleMessage> ruleMessage) {
223223
bool disruptiveAlreadyExecuted = false;
224224

225-
for (auto &a : trans->m_rules->m_defaultActions[getPhase()]) {
225+
for (auto &a : trans->m_rules->m_rulesSetPhases[getPhase()]->m_defaultActions) {
226226
if (a.get()->action_kind != actions::Action::RunTimeOnlyIfMatchKind) {
227227
continue;
228228
}
@@ -356,7 +356,7 @@ void RuleWithActions::executeTransformations(
356356
// Notice that first we make sure that won't be a t:none
357357
// on the target rule.
358358
if (none == 0) {
359-
for (auto &a : trans->m_rules->m_defaultActions[getPhase()]) {
359+
for (auto &a : trans->m_rules->m_rulesSetPhases[getPhase()]->m_defaultActions) {
360360
if (a->action_kind \
361361
!= actions::Action::RunTimeBeforeMatchAttemptKind) {
362362
continue;

src/rules_set_phases.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ int RulesSetPhases::append(RulesSetPhases *from, std::ostringstream *err) {
6161
return res;
6262
}
6363
amount_of_rules = amount_of_rules + res;
64+
65+
std::vector<std::shared_ptr<actions::Action> > *actions_from = &from->at(phase)->m_defaultActions;
66+
std::vector<std::shared_ptr<actions::Action> > *actions_to = &at(phase)->m_defaultActions;
67+
68+
for (size_t j = 0; j < actions_from->size(); j++) {
69+
actions_to->push_back(actions_from->at(j));
70+
}
6471
}
6572

6673
return amount_of_rules;

0 commit comments

Comments
 (0)