diff --git a/CHANGES b/CHANGES index 6b4a6021..ad5f625f 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,8 @@ v3.0.3 - YYYY-MMM-DD (to be released) ------------------------------------- + - Using shared_ptr instead of unique_ptr on rules exceptions + [Issue #1697 - @zimmerle, @brianp9906, @victorhora, @LeSwiss, @defanator] - Changes debuglogs schema to avoid unecessary str allocation [0xb2840 - @zimmerle] - Fix the SecUnicodeMapFile and SecUnicodeCodePage diff --git a/headers/modsecurity/rules_exceptions.h b/headers/modsecurity/rules_exceptions.h index b676e5f7..4dadfec7 100644 --- a/headers/modsecurity/rules_exceptions.h +++ b/headers/modsecurity/rules_exceptions.h @@ -73,15 +73,15 @@ class RulesExceptions { std::string *error); std::unordered_multimap, - std::unique_ptr> m_variable_update_target_by_tag; + std::shared_ptr> m_variable_update_target_by_tag; std::unordered_multimap, - std::unique_ptr> m_variable_update_target_by_msg; + std::shared_ptr> m_variable_update_target_by_msg; std::unordered_multimap> m_variable_update_target_by_id; + std::shared_ptr> m_variable_update_target_by_id; std::unordered_multimap> m_action_pre_update_target_by_id; + std::shared_ptr> m_action_pre_update_target_by_id; std::unordered_multimap> m_action_pos_update_target_by_id; + std::shared_ptr> m_action_pos_update_target_by_id; std::list m_remove_rule_by_msg; std::list m_remove_rule_by_tag; diff --git a/src/rule.cc b/src/rule.cc index 3b735733..26e4b6da 100644 --- a/src/rule.cc +++ b/src/rule.cc @@ -683,6 +683,9 @@ bool Rule::evaluate(Transaction *trans, for (auto &var : vars) { std::vector e; + if (!var) { + continue; + } var->evaluate(trans, this, &e); for (const VariableValue *v : e) { const std::string &value = v->m_value; diff --git a/src/rules_exceptions.cc b/src/rules_exceptions.cc index eed44ffa..4ac0c93e 100644 --- a/src/rules_exceptions.cc +++ b/src/rules_exceptions.cc @@ -96,7 +96,8 @@ bool RulesExceptions::loadUpdateTargetByTag(const std::string &tag, m_variable_update_target_by_tag.emplace( std::pair, std::unique_ptr>( - std::make_shared(tag), std::move(i))); + std::make_shared(tag), + std::move(i))); } return true; @@ -110,7 +111,8 @@ bool RulesExceptions::loadUpdateTargetById(double id, for (auto &i : *var) { m_variable_update_target_by_id.emplace( std::pair>(id , std::move(i))); + std::unique_ptr>(id, + std::move(i))); } return true; @@ -220,36 +222,36 @@ 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::unique_ptr>(p.first, - std::move(p.second))); + std::shared_ptr>(p.first, + p.second)); } for (auto &p : from->m_variable_update_target_by_msg) { m_variable_update_target_by_msg.emplace( std::pair, - std::unique_ptr>(p.first, - std::move(p.second))); + std::shared_ptr>(p.first, + p.second)); } for (auto &p : from->m_variable_update_target_by_id) { m_variable_update_target_by_id.emplace( std::pair>(p.first, - std::move(p.second))); + std::shared_ptr>(p.first, + p.second)); } for (auto &p : from->m_action_pos_update_target_by_id) { m_action_pos_update_target_by_id.emplace( std::pair>(p.first, - std::move(p.second))); + std::shared_ptr>(p.first, + p.second)); } for (auto &p : from->m_action_pre_update_target_by_id) { m_action_pre_update_target_by_id.emplace( std::pair>(p.first, - std::move(p.second))); + std::shared_ptr>(p.first, + p.second)); } for (auto &p : from->m_remove_rule_by_msg) {