From 34da8eeeee3f3272c7e8e0b8846ef7d1e7f4e47e Mon Sep 17 00:00:00 2001 From: Eduardo Arias Date: Fri, 9 Aug 2024 13:03:34 -0700 Subject: [PATCH] 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. --- headers/modsecurity/rule_with_actions.h | 6 ++--- src/rule_with_actions.cc | 30 ++++++++++++------------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/headers/modsecurity/rule_with_actions.h b/headers/modsecurity/rule_with_actions.h index bb63f499..26967f2a 100644 --- a/headers/modsecurity/rule_with_actions.h +++ b/headers/modsecurity/rule_with_actions.h @@ -161,9 +161,9 @@ class RuleWithActions : public Rule { const actions::transformations::Transformation &a, std::string &value, const Transaction *trans, - TransformationResults *ret, - std::string *path, - int *nth) const; + TransformationResults &ret, + std::string &path, + int &nth) const; /* actions */ actions::Action *m_disruptiveAction; diff --git a/src/rule_with_actions.cc b/src/rule_with_actions.cc index 1b76005c..7aa0e649 100644 --- a/src/rule_with_actions.cc +++ b/src/rule_with_actions.cc @@ -327,24 +327,24 @@ inline void RuleWithActions::executeTransformation( const actions::transformations::Transformation &a, std::string &value, const Transaction *trans, - TransformationResults *ret, - std::string *path, - int *nth) const { + TransformationResults &ret, + std::string &path, + int &nth) const { if (a.transform(value, trans) && m_containsMultiMatchAction) { ret.emplace_back(value, a.m_name); - (*nth)++; + nth++; } - if (path->empty()) { - path->append(*a.m_name.get()); + if (path.empty()) { + path.append(*a.m_name.get()); } else { - path->append("," + *a.m_name.get()); + path.append("," + *a.m_name.get()); } ms_dbg_a(trans, 9, " T (" + \ - std::to_string(*nth) + ") " + \ + std::to_string(nth) + ") " + \ *a.m_name.get() + ": \"" + \ utils::string::limitTo(80, value) +"\""); } @@ -353,7 +353,7 @@ void RuleWithActions::executeTransformations( const Transaction *trans, const std::string &in, TransformationResults &ret) { int none = 0; int transformations = 0; - std::string path(""); + std::string path; auto value = in; if (m_containsMultiMatchAction == true) { @@ -381,16 +381,16 @@ void RuleWithActions::executeTransformations( // FIXME: here the object needs to be a transformation already. auto t = dynamic_cast(a.get()); assert(t != nullptr); - executeTransformation(*t, value, trans, &ret, &path, - &transformations); + executeTransformation(*t, value, trans, ret, path, + transformations); } } for (const Transformation *a : m_transformations) { assert(a != nullptr); if (none == 0) { - executeTransformation(*a, value, trans, &ret, &path, - &transformations); + executeTransformation(*a, value, trans, ret, path, + transformations); } if (a->m_isNone) { none--; @@ -419,8 +419,8 @@ void RuleWithActions::executeTransformations( auto a = dynamic_cast(b.second.get()); assert(a != nullptr); if (none == 0) { - executeTransformation(*a, value, trans, &ret, &path, - &transformations); + executeTransformation(*a, value, trans, ret, path, + transformations); } if (a->m_isNone) { none--;