mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-13 21:36:00 +03:00
Makes action name a shared pointer
This commit is contained in:
parent
9c526b3647
commit
96849c07de
@ -42,7 +42,7 @@ class Action {
|
|||||||
: m_isNone(false),
|
: m_isNone(false),
|
||||||
temporaryAction(false),
|
temporaryAction(false),
|
||||||
action_kind(2),
|
action_kind(2),
|
||||||
m_name(""),
|
m_name(nullptr),
|
||||||
m_parser_payload("") {
|
m_parser_payload("") {
|
||||||
set_name_and_payload(_action);
|
set_name_and_payload(_action);
|
||||||
}
|
}
|
||||||
@ -50,7 +50,7 @@ class Action {
|
|||||||
: m_isNone(false),
|
: m_isNone(false),
|
||||||
temporaryAction(false),
|
temporaryAction(false),
|
||||||
action_kind(kind),
|
action_kind(kind),
|
||||||
m_name(""),
|
m_name(nullptr),
|
||||||
m_parser_payload("") {
|
m_parser_payload("") {
|
||||||
set_name_and_payload(_action);
|
set_name_and_payload(_action);
|
||||||
}
|
}
|
||||||
@ -77,11 +77,11 @@ class Action {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (pos == std::string::npos) {
|
if (pos == std::string::npos) {
|
||||||
m_name = data;
|
m_name = std::shared_ptr<std::string>(new std::string(data));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_name = std::string(data, 0, pos);
|
m_name = std::shared_ptr<std::string>(new std::string(data, 0, pos));
|
||||||
m_parser_payload = std::string(data, pos + 1, data.length());
|
m_parser_payload = std::string(data, pos + 1, data.length());
|
||||||
|
|
||||||
if (m_parser_payload.at(0) == '\'' && m_parser_payload.size() > 2) {
|
if (m_parser_payload.at(0) == '\'' && m_parser_payload.size() > 2) {
|
||||||
@ -93,7 +93,7 @@ class Action {
|
|||||||
bool m_isNone;
|
bool m_isNone;
|
||||||
bool temporaryAction;
|
bool temporaryAction;
|
||||||
int action_kind;
|
int action_kind;
|
||||||
std::string m_name;
|
std::shared_ptr<std::string> m_name;
|
||||||
std::string m_parser_payload;
|
std::string m_parser_payload;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1171,7 +1171,7 @@ expression:
|
|||||||
}
|
}
|
||||||
checkedActions.push_back(a);
|
checkedActions.push_back(a);
|
||||||
} else {
|
} else {
|
||||||
driver.error(@0, "The action '" + a->m_name + "' is not suitable to be part of the SecDefaultActions");
|
driver.error(@0, "The action '" + *a->m_name.get() + "' is not suitable to be part of the SecDefaultActions");
|
||||||
YYERROR;
|
YYERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
37
src/rule.cc
37
src/rule.cc
@ -262,7 +262,7 @@ void Rule::executeActionsIndependentOfChainedRuleResult(Transaction *trans,
|
|||||||
|
|
||||||
for (actions::SetVar *a : m_actionsSetVar) {
|
for (actions::SetVar *a : m_actionsSetVar) {
|
||||||
ms_dbg_a(trans, 4, "Running [independent] (non-disruptive) " \
|
ms_dbg_a(trans, 4, "Running [independent] (non-disruptive) " \
|
||||||
"action: " + a->m_name);
|
"action: " + *a->m_name.get());
|
||||||
|
|
||||||
a->evaluate(this, trans);
|
a->evaluate(this, trans);
|
||||||
}
|
}
|
||||||
@ -273,12 +273,12 @@ void Rule::executeActionsIndependentOfChainedRuleResult(Transaction *trans,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
actions::Action *a = dynamic_cast<actions::Action*>(b.second.get());
|
actions::Action *a = dynamic_cast<actions::Action*>(b.second.get());
|
||||||
if (a->isDisruptive() == true && a->m_name == "block") {
|
if (a->isDisruptive() == true && *a->m_name.get() == "block") {
|
||||||
ms_dbg_a(trans, 9, "Rule contains a `block' action");
|
ms_dbg_a(trans, 9, "Rule contains a `block' action");
|
||||||
*containsBlock = true;
|
*containsBlock = true;
|
||||||
} else if (a->m_name == "setvar") {
|
} else if (*a->m_name.get() == "setvar") {
|
||||||
ms_dbg_a(trans, 4, "Running [independent] (non-disruptive) " \
|
ms_dbg_a(trans, 4, "Running [independent] (non-disruptive) " \
|
||||||
"action: " + a->m_name);
|
"action: " + *a->m_name.get());
|
||||||
a->evaluate(this, trans, ruleMessage);
|
a->evaluate(this, trans, ruleMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -340,22 +340,21 @@ inline void Rule::executeTransformation(actions::Action *a,
|
|||||||
if (newValue != *oldValue) {
|
if (newValue != *oldValue) {
|
||||||
std::shared_ptr<std::string> u(new std::string(newValue));
|
std::shared_ptr<std::string> u(new std::string(newValue));
|
||||||
if (m_containsMultiMatchAction) {
|
if (m_containsMultiMatchAction) {
|
||||||
std::shared_ptr<std::string> t(new std::string(a->m_name));
|
ret->push_back(std::make_pair(u, a->m_name));
|
||||||
ret->push_back(std::make_pair(u, t));
|
|
||||||
(*nth)++;
|
(*nth)++;
|
||||||
}
|
}
|
||||||
*value = u;
|
*value = u;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (path->empty()) {
|
if (path->empty()) {
|
||||||
path->append(a->m_name);
|
path->append(*a->m_name.get());
|
||||||
} else {
|
} else {
|
||||||
path->append("," + a->m_name);
|
path->append("," + *a->m_name.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
ms_dbg_a(trans, 9, " T (" + \
|
ms_dbg_a(trans, 9, " T (" + \
|
||||||
std::to_string(*nth) + ") " + \
|
std::to_string(*nth) + ") " + \
|
||||||
a->m_name + ": \"" + \
|
*a->m_name.get() + ": \"" + \
|
||||||
utils::string::limitTo(80, newValue) +"\"");
|
utils::string::limitTo(80, newValue) +"\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -540,28 +539,28 @@ inline void Rule::getFinalVars(variables::Variables *vars,
|
|||||||
void Rule::executeAction(Transaction *trans,
|
void Rule::executeAction(Transaction *trans,
|
||||||
bool containsBlock, std::shared_ptr<RuleMessage> ruleMessage,
|
bool containsBlock, std::shared_ptr<RuleMessage> ruleMessage,
|
||||||
Action *a, bool defaultContext) {
|
Action *a, bool defaultContext) {
|
||||||
if (a->isDisruptive() == false && a->m_name != "block") {
|
if (a->isDisruptive() == false && *a->m_name.get() != "block") {
|
||||||
ms_dbg_a(trans, 9, "Running " \
|
ms_dbg_a(trans, 9, "Running " \
|
||||||
"action: " + a->m_name);
|
"action: " + *a->m_name.get());
|
||||||
a->evaluate(this, trans, ruleMessage);
|
a->evaluate(this, trans, ruleMessage);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (defaultContext && !containsBlock) {
|
if (defaultContext && !containsBlock) {
|
||||||
ms_dbg_a(trans, 4, "Ignoring action: " + a->m_name + \
|
ms_dbg_a(trans, 4, "Ignoring action: " + *a->m_name.get() + \
|
||||||
" (rule does not cotains block)");
|
" (rule does not cotains block)");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (trans->getRuleEngineState() == RulesSet::EnabledRuleEngine) {
|
if (trans->getRuleEngineState() == RulesSet::EnabledRuleEngine) {
|
||||||
ms_dbg_a(trans, 4, "Running (disruptive) action: " + a->m_name + \
|
ms_dbg_a(trans, 4, "Running (disruptive) action: " + *a->m_name.get() + \
|
||||||
".");
|
".");
|
||||||
a->evaluate(this, trans, ruleMessage);
|
a->evaluate(this, trans, ruleMessage);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ms_dbg_a(trans, 4, "Not running any disruptive action (or block): " \
|
ms_dbg_a(trans, 4, "Not running any disruptive action (or block): " \
|
||||||
+ a->m_name + ". SecRuleEngine is not On.");
|
+ *a->m_name.get() + ". SecRuleEngine is not On.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -581,7 +580,7 @@ void Rule::executeActionsAfterFullMatch(Transaction *trans,
|
|||||||
|
|
||||||
for (actions::Tag *a : this->m_actionsTag) {
|
for (actions::Tag *a : this->m_actionsTag) {
|
||||||
ms_dbg_a(trans, 4, "Running (non-disruptive) action: " \
|
ms_dbg_a(trans, 4, "Running (non-disruptive) action: " \
|
||||||
+ a->m_name);
|
+ *a->m_name.get());
|
||||||
a->evaluate(this, trans, ruleMessage);
|
a->evaluate(this, trans, ruleMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -811,12 +810,12 @@ std::vector<actions::Action *> Rule::getActionsByName(const std::string& name,
|
|||||||
Transaction *trans) {
|
Transaction *trans) {
|
||||||
std::vector<actions::Action *> ret;
|
std::vector<actions::Action *> ret;
|
||||||
for (auto &z : m_actionsRuntimePos) {
|
for (auto &z : m_actionsRuntimePos) {
|
||||||
if (z->m_name == name) {
|
if (*z->m_name.get() == name) {
|
||||||
ret.push_back(z);
|
ret.push_back(z);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (auto &z : m_actionsRuntimePre) {
|
for (auto &z : m_actionsRuntimePre) {
|
||||||
if (z->m_name == name) {
|
if (*z->m_name.get() == name) {
|
||||||
ret.push_back(z);
|
ret.push_back(z);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -826,7 +825,7 @@ std::vector<actions::Action *> Rule::getActionsByName(const std::string& name,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
actions::Action *z = dynamic_cast<actions::Action*>(b.second.get());
|
actions::Action *z = dynamic_cast<actions::Action*>(b.second.get());
|
||||||
if (z->m_name == name) {
|
if (*z->m_name.get() == name) {
|
||||||
ret.push_back(z);
|
ret.push_back(z);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -836,7 +835,7 @@ std::vector<actions::Action *> Rule::getActionsByName(const std::string& name,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
actions::Action *z = dynamic_cast<actions::Action*>(b.second.get());
|
actions::Action *z = dynamic_cast<actions::Action*>(b.second.get());
|
||||||
if (z->m_name == name) {
|
if (*z->m_name.get() == name) {
|
||||||
ret.push_back(z);
|
ret.push_back(z);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user