mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-13 21:36:00 +03:00
Uses shared_ptr on variable names
This commit is contained in:
parent
9d062f53a7
commit
003a8e8e5f
@ -37,33 +37,32 @@ namespace collection {
|
||||
class Variable {
|
||||
public:
|
||||
explicit Variable(const std::string *key) :
|
||||
m_key(key),
|
||||
m_value(),
|
||||
m_dynamic_value(false),
|
||||
m_dynamic_key(false),
|
||||
m_dynamic(true) { }
|
||||
m_dynamic(true) {
|
||||
m_key.reset(new std::string(*key));
|
||||
}
|
||||
Variable(const std::string *key, const std::string *value) :
|
||||
m_key(key),
|
||||
m_value(value),
|
||||
m_dynamic_value(false),
|
||||
m_dynamic_key(false),
|
||||
m_dynamic(true) { }
|
||||
m_dynamic(true) {
|
||||
m_key.reset(new std::string(*key));
|
||||
m_value.reset(new std::string(*value));
|
||||
|
||||
}
|
||||
explicit Variable(const std::shared_ptr<std::string> key) :
|
||||
m_dynamic(true) {
|
||||
m_key = key;
|
||||
}
|
||||
Variable(std::shared_ptr<std::string> key, std::shared_ptr<std::string> value) :
|
||||
m_dynamic(true) {
|
||||
m_key = key;
|
||||
m_value = value;
|
||||
|
||||
}
|
||||
~Variable() {
|
||||
if (m_dynamic_value) {
|
||||
delete m_value;
|
||||
}
|
||||
if (m_dynamic_key) {
|
||||
delete m_key;
|
||||
}
|
||||
}
|
||||
|
||||
const std::string *m_key;
|
||||
const std::string *m_value;
|
||||
bool m_dynamic_value;
|
||||
bool m_dynamic_key;
|
||||
bool m_dynamic;
|
||||
std::shared_ptr<std::string> m_key;
|
||||
std::shared_ptr<std::string> m_value;
|
||||
std::list<std::unique_ptr<VariableOrigin>> m_orign;
|
||||
bool m_dynamic;
|
||||
};
|
||||
|
||||
} // namespace collection
|
||||
|
@ -60,7 +60,7 @@ class RulesExceptions {
|
||||
std::unique_ptr<std::vector<std::unique_ptr<Variables::Variable> > > var,
|
||||
std::string *error);
|
||||
|
||||
std::unordered_multimap<std::string, std::unique_ptr<Variables::Variable>> m_variable_update_target_by_tag;
|
||||
std::unordered_multimap<std::shared_ptr<std::string>, std::unique_ptr<Variables::Variable>> m_variable_update_target_by_tag;
|
||||
std::unordered_multimap<double, std::unique_ptr<Variables::Variable>> m_variable_update_target_by_id;
|
||||
std::list<std::string> m_remove_rule_by_msg;
|
||||
|
||||
|
@ -43,8 +43,6 @@ AnchoredSetVariable::~AnchoredSetVariable() {
|
||||
void AnchoredSetVariable::unset() {
|
||||
for (const auto& x : *this) {
|
||||
collection::Variable *var = x.second;
|
||||
delete var->m_key;
|
||||
var->m_key = NULL;
|
||||
delete var;
|
||||
}
|
||||
clear();
|
||||
@ -61,7 +59,6 @@ void AnchoredSetVariable::set(const std::string &key,
|
||||
origin->m_offset = offset;
|
||||
origin->m_length = len;
|
||||
|
||||
var->m_dynamic_value = true;
|
||||
var->m_dynamic = false;
|
||||
var->m_orign.push_back(std::move(origin));
|
||||
emplace(key, var);
|
||||
@ -78,7 +75,6 @@ void AnchoredSetVariable::set(const std::string &key,
|
||||
origin->m_offset = offset;
|
||||
origin->m_length = value.size();
|
||||
|
||||
var->m_dynamic_value = true;
|
||||
var->m_dynamic = false;
|
||||
var->m_orign.push_back(std::move(origin));
|
||||
emplace(key, var);
|
||||
|
@ -38,15 +38,17 @@ AnchoredVariable::AnchoredVariable(Transaction *t,
|
||||
m_name.append(name);
|
||||
m_var = new collection::Variable(&m_name);
|
||||
m_var->m_dynamic = false;
|
||||
m_var->m_value = &m_value;
|
||||
m_var->m_value.reset(&m_value);
|
||||
}
|
||||
|
||||
|
||||
AnchoredVariable::~AnchoredVariable() {
|
||||
/*
|
||||
if (m_var) {
|
||||
delete (m_var);
|
||||
m_var = NULL;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
24
src/rule.cc
24
src/rule.cc
@ -431,16 +431,16 @@ std::list<std::pair<std::shared_ptr<std::string>,
|
||||
|
||||
std::vector<std::unique_ptr<collection::Variable>> Rule::getFinalVars(
|
||||
Transaction *trans) {
|
||||
std::list<const std::string*> exclusions;
|
||||
std::list<const std::string*> exclusions_update_by_tag_remove;
|
||||
std::list<const std::string*> exclusions_update_by_id_remove;
|
||||
std::list<std::shared_ptr<std::string>> exclusions;
|
||||
std::list<std::shared_ptr<std::string>> exclusions_update_by_tag_remove;
|
||||
std::list<std::shared_ptr<std::string>> exclusions_update_by_id_remove;
|
||||
std::vector<Variables::Variable *> variables;
|
||||
std::vector<std::unique_ptr<collection::Variable>> finalVars;
|
||||
|
||||
std::copy (m_variables->begin(), m_variables->end(), std::back_inserter(variables));
|
||||
|
||||
for (auto &a : trans->m_rules->m_exceptions.m_variable_update_target_by_tag) {
|
||||
if (containsTag(a.first, trans) == false) {
|
||||
if (containsTag(*a.first.get(), trans) == false) {
|
||||
continue;
|
||||
}
|
||||
if (a.second->m_isExclusion) {
|
||||
@ -449,7 +449,7 @@ std::vector<std::unique_ptr<collection::Variable>> Rule::getFinalVars(
|
||||
for (auto &y : z) {
|
||||
exclusions_update_by_tag_remove.push_back(y->m_key);
|
||||
}
|
||||
exclusions_update_by_tag_remove.push_back(&a.second->m_name);
|
||||
exclusions_update_by_tag_remove.push_back(std::make_shared<std::string>(a.second->m_name));
|
||||
|
||||
} else {
|
||||
Variable *b = a.second.get();
|
||||
@ -467,7 +467,7 @@ std::vector<std::unique_ptr<collection::Variable>> Rule::getFinalVars(
|
||||
for (auto &y : z) {
|
||||
exclusions_update_by_id_remove.push_back(y->m_key);
|
||||
}
|
||||
exclusions_update_by_id_remove.push_back(&a.second->m_name);
|
||||
exclusions_update_by_id_remove.push_back(std::make_shared<std::string>(a.second->m_name));
|
||||
} else {
|
||||
Variable *b = a.second.get();
|
||||
variables.push_back(b);
|
||||
@ -482,7 +482,7 @@ std::vector<std::unique_ptr<collection::Variable>> Rule::getFinalVars(
|
||||
for (auto &y : z) {
|
||||
exclusions.push_back(y->m_key);
|
||||
}
|
||||
exclusions.push_back(&variable->m_name);
|
||||
// exclusions.push_back(std::make_shared<std::string>(&variable->m_name));
|
||||
}
|
||||
}
|
||||
|
||||
@ -497,9 +497,9 @@ std::vector<std::unique_ptr<collection::Variable>> Rule::getFinalVars(
|
||||
|
||||
variable->evaluateInternal(trans, this, &e);
|
||||
for (const collection::Variable *v : e) {
|
||||
const std::string *key = v->m_key;
|
||||
const std::shared_ptr<std::string> key = v->m_key;
|
||||
if (std::find_if(exclusions.begin(), exclusions.end(),
|
||||
[key](const std::string *m) -> bool { return *key == *m; })
|
||||
[key](std::shared_ptr<std::string> m) -> bool { return *key == *m.get(); })
|
||||
!= exclusions.end()) {
|
||||
#ifndef NO_LOGS
|
||||
trans->debug(9, "Variable: " + *key +
|
||||
@ -513,7 +513,7 @@ std::vector<std::unique_ptr<collection::Variable>> Rule::getFinalVars(
|
||||
}
|
||||
if (std::find_if(exclusions_update_by_tag_remove.begin(),
|
||||
exclusions_update_by_tag_remove.end(),
|
||||
[key](const std::string *m) -> bool { return *key == *m; })
|
||||
[key](std::shared_ptr<std::string> m) -> bool { return *key == *m.get(); })
|
||||
!= exclusions_update_by_tag_remove.end()) {
|
||||
#ifndef NO_LOGS
|
||||
trans->debug(9, "Variable: " + *key +
|
||||
@ -529,7 +529,7 @@ std::vector<std::unique_ptr<collection::Variable>> Rule::getFinalVars(
|
||||
|
||||
if (std::find_if(exclusions_update_by_id_remove.begin(),
|
||||
exclusions_update_by_id_remove.end(),
|
||||
[key](const std::string *m) -> bool { return *key == *m; })
|
||||
[key](std::shared_ptr<std::string> m) -> bool { return *key == *m.get(); })
|
||||
!= exclusions_update_by_id_remove.end()) {
|
||||
#ifndef NO_LOGS
|
||||
trans->debug(9, "Variable: " + *key +
|
||||
@ -621,8 +621,6 @@ std::vector<std::unique_ptr<collection::Variable>> Rule::getFinalVars(
|
||||
std::unique_ptr<collection::Variable> var(new collection::Variable(
|
||||
new std::string(*v->m_key),
|
||||
new std::string(*v->m_value)));
|
||||
var->m_dynamic_value = true;
|
||||
var->m_dynamic_key = true;
|
||||
for (auto &i : v->m_orign) {
|
||||
std::unique_ptr<VariableOrigin> origin(new VariableOrigin());
|
||||
origin->m_offset = i->m_offset;
|
||||
|
@ -44,7 +44,7 @@ bool RulesExceptions::loadUpdateTargetByTag(const std::string &tag,
|
||||
std::string *error) {
|
||||
|
||||
for (auto &i : *var) {
|
||||
m_variable_update_target_by_tag.emplace(std::pair<std::string, std::unique_ptr<Variables::Variable>>(tag, std::move(i)));
|
||||
m_variable_update_target_by_tag.emplace(std::pair<std::shared_ptr<std::string>, std::unique_ptr<Variables::Variable>>(std::make_shared<std::string>(tag), std::move(i)));
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -164,7 +164,7 @@ bool RulesExceptions::merge(RulesExceptions& from) {
|
||||
}
|
||||
|
||||
for (auto &p : from.m_variable_update_target_by_tag) {
|
||||
m_variable_update_target_by_tag.emplace(std::pair<std::string, std::unique_ptr<Variables::Variable>>(p.first, std::move(p.second)));
|
||||
m_variable_update_target_by_tag.emplace(std::pair<std::shared_ptr<std::string>, std::unique_ptr<Variables::Variable>>(p.first, std::move(p.second)));
|
||||
}
|
||||
|
||||
for (auto &p : from.m_variable_update_target_by_id) {
|
||||
|
@ -64,7 +64,7 @@ void RemoteUser::evaluate(Transaction *transaction,
|
||||
transaction->m_variableRemoteUser.assign(std::string(base64, 0, pos));
|
||||
|
||||
var = new collection::Variable(l->at(0)->m_key,
|
||||
&transaction->m_variableRemoteUser);
|
||||
std::make_shared<std::string>(transaction->m_variableRemoteUser));
|
||||
|
||||
for (auto &i : l->at(0)->m_orign) {
|
||||
std::unique_ptr<VariableOrigin> origin(new VariableOrigin());
|
||||
|
@ -143,7 +143,6 @@ class VariableModificatorCount : public Variable {
|
||||
res = new std::string(std::to_string(count));
|
||||
|
||||
val = new collection::Variable(&m_name, res);
|
||||
val->m_dynamic_value = true;
|
||||
val->m_dynamic = true;
|
||||
|
||||
l->push_back(val);
|
||||
|
@ -127,7 +127,6 @@ void XML::evaluate(Transaction *t,
|
||||
if (content != NULL) {
|
||||
collection::Variable *var = new collection::Variable(&m_name,
|
||||
new std::string(content));
|
||||
var->m_dynamic_value = true;
|
||||
l->push_back(var);
|
||||
xmlFree(content);
|
||||
}
|
||||
|
@ -41,7 +41,6 @@ class XML_NoDictElement : public Variable {
|
||||
m_plain("[XML document tree]"),
|
||||
m_var(&m_name, &m_plain) {
|
||||
m_var.m_dynamic = false;
|
||||
m_var.m_dynamic_value = false;
|
||||
}
|
||||
|
||||
void evaluate(Transaction *transaction,
|
||||
|
Loading…
x
Reference in New Issue
Block a user