Skip to content

Commit fa5f378

Browse files
author
Felipe Zimmerle
committed
Using shared_ptr instead of unique_ptr on rules exceptions
1 parent e63344c commit fa5f378

File tree

4 files changed

+24
-17
lines changed

4 files changed

+24
-17
lines changed

CHANGES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
v3.0.3 - YYYY-MMM-DD (to be released)
22
-------------------------------------
33

4+
- Using shared_ptr instead of unique_ptr on rules exceptions
5+
[Issue #1697 - @zimmerle, @brianp9906, @victorhora, @LeSwiss, @defanator]
46
- Changes debuglogs schema to avoid unecessary str allocation
57
[0xb2840 - @zimmerle]
68
- Fix the SecUnicodeMapFile and SecUnicodeCodePage

headers/modsecurity/rules_exceptions.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,15 @@ class RulesExceptions {
7373
std::string *error);
7474

7575
std::unordered_multimap<std::shared_ptr<std::string>,
76-
std::unique_ptr<Variables::Variable>> m_variable_update_target_by_tag;
76+
std::shared_ptr<Variables::Variable>> m_variable_update_target_by_tag;
7777
std::unordered_multimap<std::shared_ptr<std::string>,
78-
std::unique_ptr<Variables::Variable>> m_variable_update_target_by_msg;
78+
std::shared_ptr<Variables::Variable>> m_variable_update_target_by_msg;
7979
std::unordered_multimap<double,
80-
std::unique_ptr<Variables::Variable>> m_variable_update_target_by_id;
80+
std::shared_ptr<Variables::Variable>> m_variable_update_target_by_id;
8181
std::unordered_multimap<double,
82-
std::unique_ptr<actions::Action>> m_action_pre_update_target_by_id;
82+
std::shared_ptr<actions::Action>> m_action_pre_update_target_by_id;
8383
std::unordered_multimap<double,
84-
std::unique_ptr<actions::Action>> m_action_pos_update_target_by_id;
84+
std::shared_ptr<actions::Action>> m_action_pos_update_target_by_id;
8585
std::list<std::string> m_remove_rule_by_msg;
8686
std::list<std::string> m_remove_rule_by_tag;
8787

src/rule.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,9 @@ bool Rule::evaluate(Transaction *trans,
683683

684684
for (auto &var : vars) {
685685
std::vector<const VariableValue *> e;
686+
if (!var) {
687+
continue;
688+
}
686689
var->evaluate(trans, this, &e);
687690
for (const VariableValue *v : e) {
688691
const std::string &value = v->m_value;

src/rules_exceptions.cc

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ bool RulesExceptions::loadUpdateTargetByTag(const std::string &tag,
9696
m_variable_update_target_by_tag.emplace(
9797
std::pair<std::shared_ptr<std::string>,
9898
std::unique_ptr<Variables::Variable>>(
99-
std::make_shared<std::string>(tag), std::move(i)));
99+
std::make_shared<std::string>(tag),
100+
std::move(i)));
100101
}
101102

102103
return true;
@@ -110,7 +111,8 @@ bool RulesExceptions::loadUpdateTargetById(double id,
110111
for (auto &i : *var) {
111112
m_variable_update_target_by_id.emplace(
112113
std::pair<double,
113-
std::unique_ptr<Variables::Variable>>(id , std::move(i)));
114+
std::unique_ptr<Variables::Variable>>(id,
115+
std::move(i)));
114116
}
115117

116118
return true;
@@ -220,36 +222,36 @@ bool RulesExceptions::merge(RulesExceptions *from) {
220222
for (auto &p : from->m_variable_update_target_by_tag) {
221223
m_variable_update_target_by_tag.emplace(
222224
std::pair<std::shared_ptr<std::string>,
223-
std::unique_ptr<Variables::Variable>>(p.first,
224-
std::move(p.second)));
225+
std::shared_ptr<Variables::Variable>>(p.first,
226+
p.second));
225227
}
226228

227229
for (auto &p : from->m_variable_update_target_by_msg) {
228230
m_variable_update_target_by_msg.emplace(
229231
std::pair<std::shared_ptr<std::string>,
230-
std::unique_ptr<Variables::Variable>>(p.first,
231-
std::move(p.second)));
232+
std::shared_ptr<Variables::Variable>>(p.first,
233+
p.second));
232234
}
233235

234236
for (auto &p : from->m_variable_update_target_by_id) {
235237
m_variable_update_target_by_id.emplace(
236238
std::pair<double,
237-
std::unique_ptr<Variables::Variable>>(p.first,
238-
std::move(p.second)));
239+
std::shared_ptr<Variables::Variable>>(p.first,
240+
p.second));
239241
}
240242

241243
for (auto &p : from->m_action_pos_update_target_by_id) {
242244
m_action_pos_update_target_by_id.emplace(
243245
std::pair<double,
244-
std::unique_ptr<actions::Action>>(p.first,
245-
std::move(p.second)));
246+
std::shared_ptr<actions::Action>>(p.first,
247+
p.second));
246248
}
247249

248250
for (auto &p : from->m_action_pre_update_target_by_id) {
249251
m_action_pre_update_target_by_id.emplace(
250252
std::pair<double,
251-
std::unique_ptr<actions::Action>>(p.first,
252-
std::move(p.second)));
253+
std::shared_ptr<actions::Action>>(p.first,
254+
p.second));
253255
}
254256

255257
for (auto &p : from->m_remove_rule_by_msg) {

0 commit comments

Comments
 (0)