Having default actions as o shared pointer

This commit is contained in:
Felipe Zimmerle 2019-01-22 09:15:29 -03:00
parent 9d158611cf
commit 6b0ad8049a
No known key found for this signature in database
GPG Key ID: E6DFB08CE8B11277
5 changed files with 775 additions and 776 deletions

View File

@ -204,13 +204,10 @@ class RulesSetProperties {
int i = 0;
for (i = 0; i < modsecurity::Phases::NUMBER_OF_PHASES; i++) {
std::vector<actions::Action *> *tmp = &m_defaultActions[i];
std::vector<std::shared_ptr<actions::Action> > *tmp = \
&m_defaultActions[i];
while (tmp->empty() == false) {
actions::Action *a = tmp->back();
tmp->pop_back();
if (a->refCountDecreaseAndCheck()) {
a = NULL;
}
}
}
@ -342,8 +339,8 @@ class RulesSetProperties {
}
static int mergeProperties(RulesSetProperties *from, RulesSetProperties *to,
std::ostringstream *err) {
static int mergeProperties(RulesSetProperties *from,
RulesSetProperties *to, std::ostringstream *err) {
merge_ruleengine_value(to->m_secRuleEngine, from->m_secRuleEngine,
PropertyNotSetRuleEngine);
@ -414,13 +411,12 @@ class RulesSetProperties {
}
for (int i = 0; i < modsecurity::Phases::NUMBER_OF_PHASES; i++) {
std::vector<actions::Action *> *actions_from = \
from->m_defaultActions+i;
std::vector<actions::Action *> *actions_to = to->m_defaultActions+i;
std::vector<std::shared_ptr<actions::Action> > *actions_from = \
&from->m_defaultActions[i];
std::vector<std::shared_ptr<actions::Action> > *actions_to = \
&to->m_defaultActions[i];
for (size_t j = 0; j < actions_from->size(); j++) {
actions::Action *action = actions_from->at(j);
action->refCountIncrease();
actions_to->push_back(action);
actions_to->push_back(actions_from->at(j));
}
}
@ -485,7 +481,8 @@ class RulesSetProperties {
ConfigString m_uploadTmpDirectory;
ConfigString m_secArgumentSeparator;
ConfigString m_secWebAppId;
std::vector<actions::Action *> m_defaultActions[modsecurity::Phases::NUMBER_OF_PHASES];
std::vector<std::shared_ptr<actions::Action> > \
m_defaultActions[modsecurity::Phases::NUMBER_OF_PHASES];
ConfigUnicodeMap m_unicodeMapTable;
};

View File

@ -33,7 +33,7 @@ bool Block::evaluate(Rule *rule, Transaction *transaction,
std::shared_ptr<RuleMessage> rm) {
ms_dbg_a(transaction, 8, "Marking request as disruptive.");
for (Action *a : transaction->m_rules->m_defaultActions[rule->m_phase]) {
for (auto &a : transaction->m_rules->m_defaultActions[rule->m_phase]) {
if (a->isDisruptive() == false) {
continue;
}

File diff suppressed because it is too large Load Diff

View File

@ -1194,7 +1194,8 @@ expression:
}
for (actions::Action *a : checkedActions) {
driver.m_defaultActions[definedPhase].push_back(a);
driver.m_defaultActions[definedPhase].push_back(
std::unique_ptr<actions::Action>(a));
}
delete actions;

View File

@ -389,13 +389,13 @@ std::list<std::pair<std::shared_ptr<std::string>,
// Notice that first we make sure that won't be a t:none
// on the target rule.
if (none == 0) {
for (Action *a : trans->m_rules->m_defaultActions[this->m_phase]) {
for (auto &a : trans->m_rules->m_defaultActions[this->m_phase]) {
if (a->action_kind \
!= actions::Action::RunTimeBeforeMatchAttemptKind) {
continue;
}
executeTransformation(a, &value, trans, &ret, &path,
executeTransformation(a.get(), &value, trans, &ret, &path,
&transformations);
}
}
@ -570,12 +570,12 @@ void Rule::executeActionsAfterFullMatch(Transaction *trans,
bool containsBlock, std::shared_ptr<RuleMessage> ruleMessage) {
bool disruptiveAlreadyExecuted = false;
for (Action *a : trans->m_rules->m_defaultActions[this->m_phase]) {
if (a->action_kind != actions::Action::RunTimeOnlyIfMatchKind) {
for (auto &a : trans->m_rules->m_defaultActions[this->m_phase]) {
if (a.get()->action_kind != actions::Action::RunTimeOnlyIfMatchKind) {
continue;
}
if (!a->isDisruptive()) {
executeAction(trans, containsBlock, ruleMessage, a, true);
if (!a.get()->isDisruptive()) {
executeAction(trans, containsBlock, ruleMessage, a.get(), true);
}
}