Skip to content

Commit 45793dd

Browse files
committed
Pass RuleWithActions::executeTransformation arguments by reference
- This function already expects these arguments not to be null pointers, doesn't validate them and just dereference them. - In order to make this explicit and enforced by the compiler, they're now passed as references.
1 parent 1757c16 commit 45793dd

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

headers/modsecurity/rule_with_actions.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,9 @@ class RuleWithActions : public Rule {
161161
const actions::transformations::Transformation &a,
162162
std::string &value,
163163
const Transaction *trans,
164-
TransformationResults *ret,
165-
std::string *path,
166-
int *nth) const;
164+
TransformationResults &ret,
165+
std::string &path,
166+
int &nth) const;
167167

168168
/* actions */
169169
actions::Action *m_disruptiveAction;

src/rule_with_actions.cc

+16-16
Original file line numberDiff line numberDiff line change
@@ -327,24 +327,24 @@ inline void RuleWithActions::executeTransformation(
327327
const actions::transformations::Transformation &a,
328328
std::string &value,
329329
const Transaction *trans,
330-
TransformationResults *ret,
331-
std::string *path,
332-
int *nth) const {
330+
TransformationResults &ret,
331+
std::string &path,
332+
int &nth) const {
333333

334334
if (a.transform(value, trans) &&
335335
m_containsMultiMatchAction) {
336-
ret->push_back({value, a.m_name});
337-
(*nth)++;
336+
ret.push_back({value, a.m_name});
337+
nth++;
338338
}
339339

340-
if (path->empty()) {
341-
path->append(*a.m_name.get());
340+
if (path.empty()) {
341+
path.append(*a.m_name.get());
342342
} else {
343-
path->append("," + *a.m_name.get());
343+
path.append("," + *a.m_name.get());
344344
}
345345

346346
ms_dbg_a(trans, 9, " T (" + \
347-
std::to_string(*nth) + ") " + \
347+
std::to_string(nth) + ") " + \
348348
*a.m_name.get() + ": \"" + \
349349
utils::string::limitTo(80, value) +"\"");
350350
}
@@ -353,7 +353,7 @@ void RuleWithActions::executeTransformations(
353353
const Transaction *trans, const std::string &in, TransformationResults &ret) {
354354
int none = 0;
355355
int transformations = 0;
356-
std::string path("");
356+
std::string path;
357357
auto value = in;
358358

359359
if (m_containsMultiMatchAction == true) {
@@ -381,16 +381,16 @@ void RuleWithActions::executeTransformations(
381381
// FIXME: here the object needs to be a transformation already.
382382
auto t = dynamic_cast<const Transformation*>(a.get());
383383
assert(t != nullptr);
384-
executeTransformation(*t, value, trans, &ret, &path,
385-
&transformations);
384+
executeTransformation(*t, value, trans, ret, path,
385+
transformations);
386386
}
387387
}
388388

389389
for (const Transformation *a : m_transformations) {
390390
assert(a != nullptr);
391391
if (none == 0) {
392-
executeTransformation(*a, value, trans, &ret, &path,
393-
&transformations);
392+
executeTransformation(*a, value, trans, ret, path,
393+
transformations);
394394
}
395395
if (a->m_isNone) {
396396
none--;
@@ -419,8 +419,8 @@ void RuleWithActions::executeTransformations(
419419
auto a = dynamic_cast<const Transformation*>(b.second.get());
420420
assert(a != nullptr);
421421
if (none == 0) {
422-
executeTransformation(*a, value, trans, &ret, &path,
423-
&transformations);
422+
executeTransformation(*a, value, trans, ret, path,
423+
transformations);
424424
}
425425
if (a->m_isNone) {
426426
none--;

0 commit comments

Comments
 (0)