Skip to content

Commit 96849c0

Browse files
committed
Makes action name a shared pointer
1 parent 9c526b3 commit 96849c0

File tree

3 files changed

+24
-25
lines changed

3 files changed

+24
-25
lines changed

headers/modsecurity/actions/action.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ class Action {
4242
: m_isNone(false),
4343
temporaryAction(false),
4444
action_kind(2),
45-
m_name(""),
45+
m_name(nullptr),
4646
m_parser_payload("") {
4747
set_name_and_payload(_action);
4848
}
4949
explicit Action(const std::string& _action, int kind)
5050
: m_isNone(false),
5151
temporaryAction(false),
5252
action_kind(kind),
53-
m_name(""),
53+
m_name(nullptr),
5454
m_parser_payload("") {
5555
set_name_and_payload(_action);
5656
}
@@ -77,11 +77,11 @@ class Action {
7777
}
7878

7979
if (pos == std::string::npos) {
80-
m_name = data;
80+
m_name = std::shared_ptr<std::string>(new std::string(data));
8181
return;
8282
}
8383

84-
m_name = std::string(data, 0, pos);
84+
m_name = std::shared_ptr<std::string>(new std::string(data, 0, pos));
8585
m_parser_payload = std::string(data, pos + 1, data.length());
8686

8787
if (m_parser_payload.at(0) == '\'' && m_parser_payload.size() > 2) {
@@ -93,7 +93,7 @@ class Action {
9393
bool m_isNone;
9494
bool temporaryAction;
9595
int action_kind;
96-
std::string m_name;
96+
std::shared_ptr<std::string> m_name;
9797
std::string m_parser_payload;
9898

9999
/**

src/parser/seclang-parser.yy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1171,7 +1171,7 @@ expression:
11711171
}
11721172
checkedActions.push_back(a);
11731173
} else {
1174-
driver.error(@0, "The action '" + a->m_name + "' is not suitable to be part of the SecDefaultActions");
1174+
driver.error(@0, "The action '" + *a->m_name.get() + "' is not suitable to be part of the SecDefaultActions");
11751175
YYERROR;
11761176
}
11771177
}

src/rule.cc

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ void Rule::executeActionsIndependentOfChainedRuleResult(Transaction *trans,
262262

263263
for (actions::SetVar *a : m_actionsSetVar) {
264264
ms_dbg_a(trans, 4, "Running [independent] (non-disruptive) " \
265-
"action: " + a->m_name);
265+
"action: " + *a->m_name.get());
266266

267267
a->evaluate(this, trans);
268268
}
@@ -273,12 +273,12 @@ void Rule::executeActionsIndependentOfChainedRuleResult(Transaction *trans,
273273
continue;
274274
}
275275
actions::Action *a = dynamic_cast<actions::Action*>(b.second.get());
276-
if (a->isDisruptive() == true && a->m_name == "block") {
276+
if (a->isDisruptive() == true && *a->m_name.get() == "block") {
277277
ms_dbg_a(trans, 9, "Rule contains a `block' action");
278278
*containsBlock = true;
279-
} else if (a->m_name == "setvar") {
279+
} else if (*a->m_name.get() == "setvar") {
280280
ms_dbg_a(trans, 4, "Running [independent] (non-disruptive) " \
281-
"action: " + a->m_name);
281+
"action: " + *a->m_name.get());
282282
a->evaluate(this, trans, ruleMessage);
283283
}
284284
}
@@ -340,22 +340,21 @@ inline void Rule::executeTransformation(actions::Action *a,
340340
if (newValue != *oldValue) {
341341
std::shared_ptr<std::string> u(new std::string(newValue));
342342
if (m_containsMultiMatchAction) {
343-
std::shared_ptr<std::string> t(new std::string(a->m_name));
344-
ret->push_back(std::make_pair(u, t));
343+
ret->push_back(std::make_pair(u, a->m_name));
345344
(*nth)++;
346345
}
347346
*value = u;
348347
}
349348

350349
if (path->empty()) {
351-
path->append(a->m_name);
350+
path->append(*a->m_name.get());
352351
} else {
353-
path->append("," + a->m_name);
352+
path->append("," + *a->m_name.get());
354353
}
355354

356355
ms_dbg_a(trans, 9, " T (" + \
357356
std::to_string(*nth) + ") " + \
358-
a->m_name + ": \"" + \
357+
*a->m_name.get() + ": \"" + \
359358
utils::string::limitTo(80, newValue) +"\"");
360359
}
361360

@@ -540,28 +539,28 @@ inline void Rule::getFinalVars(variables::Variables *vars,
540539
void Rule::executeAction(Transaction *trans,
541540
bool containsBlock, std::shared_ptr<RuleMessage> ruleMessage,
542541
Action *a, bool defaultContext) {
543-
if (a->isDisruptive() == false && a->m_name != "block") {
542+
if (a->isDisruptive() == false && *a->m_name.get() != "block") {
544543
ms_dbg_a(trans, 9, "Running " \
545-
"action: " + a->m_name);
544+
"action: " + *a->m_name.get());
546545
a->evaluate(this, trans, ruleMessage);
547546
return;
548547
}
549548

550549
if (defaultContext && !containsBlock) {
551-
ms_dbg_a(trans, 4, "Ignoring action: " + a->m_name + \
550+
ms_dbg_a(trans, 4, "Ignoring action: " + *a->m_name.get() + \
552551
" (rule does not cotains block)");
553552
return;
554553
}
555554

556555
if (trans->getRuleEngineState() == RulesSet::EnabledRuleEngine) {
557-
ms_dbg_a(trans, 4, "Running (disruptive) action: " + a->m_name + \
556+
ms_dbg_a(trans, 4, "Running (disruptive) action: " + *a->m_name.get() + \
558557
".");
559558
a->evaluate(this, trans, ruleMessage);
560559
return;
561560
}
562561

563562
ms_dbg_a(trans, 4, "Not running any disruptive action (or block): " \
564-
+ a->m_name + ". SecRuleEngine is not On.");
563+
+ *a->m_name.get() + ". SecRuleEngine is not On.");
565564
}
566565

567566

@@ -581,7 +580,7 @@ void Rule::executeActionsAfterFullMatch(Transaction *trans,
581580

582581
for (actions::Tag *a : this->m_actionsTag) {
583582
ms_dbg_a(trans, 4, "Running (non-disruptive) action: " \
584-
+ a->m_name);
583+
+ *a->m_name.get());
585584
a->evaluate(this, trans, ruleMessage);
586585
}
587586

@@ -811,12 +810,12 @@ std::vector<actions::Action *> Rule::getActionsByName(const std::string& name,
811810
Transaction *trans) {
812811
std::vector<actions::Action *> ret;
813812
for (auto &z : m_actionsRuntimePos) {
814-
if (z->m_name == name) {
813+
if (*z->m_name.get() == name) {
815814
ret.push_back(z);
816815
}
817816
}
818817
for (auto &z : m_actionsRuntimePre) {
819-
if (z->m_name == name) {
818+
if (*z->m_name.get() == name) {
820819
ret.push_back(z);
821820
}
822821
}
@@ -826,7 +825,7 @@ std::vector<actions::Action *> Rule::getActionsByName(const std::string& name,
826825
continue;
827826
}
828827
actions::Action *z = dynamic_cast<actions::Action*>(b.second.get());
829-
if (z->m_name == name) {
828+
if (*z->m_name.get() == name) {
830829
ret.push_back(z);
831830
}
832831
}
@@ -836,7 +835,7 @@ std::vector<actions::Action *> Rule::getActionsByName(const std::string& name,
836835
continue;
837836
}
838837
actions::Action *z = dynamic_cast<actions::Action*>(b.second.get());
839-
if (z->m_name == name) {
838+
if (*z->m_name.get() == name) {
840839
ret.push_back(z);
841840
}
842841
}

0 commit comments

Comments
 (0)