mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-09-29 11:16:33 +03:00
Updated Transformation::evaluate signature to allow for in-place updates, removing unnecessary heap allocated copies.
- Renamed Transformation::evaluate to Transformation::transform to avoid confusion with Action's overload methods. - Updated Transformation::transform signature to receive the value by reference and perform the transformation inline, if possible. - Some transformations still need to use a temporary std::string to perform their work, and then copy the result back. - Made Transformation::transform methods const and updated Transaction parameter to be const. - Transaction parameter could not be removed because it's used by just a single transformation, UrlDecodeUni. - Removed std::string Action::evaluate(const std::string &exp, Transaction *transaction); which was only implemented by Transformation but was not used from the base class, but only after downcasting to Transformation, so it can just be declared there (and not pollute other actions with a default member implementation -that does nothing- which is never called).
This commit is contained in:
@@ -13,26 +13,19 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
|
||||
#endif
|
||||
|
||||
#include "modsecurity/intervention.h"
|
||||
#include "modsecurity/rule.h"
|
||||
#include "modsecurity/rule_with_actions.h"
|
||||
|
||||
#ifndef HEADERS_MODSECURITY_ACTIONS_ACTION_H_
|
||||
#define HEADERS_MODSECURITY_ACTIONS_ACTION_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
namespace modsecurity {
|
||||
class Transaction;
|
||||
class RuleWithOperator;
|
||||
class RuleWithActions;
|
||||
class RuleMessage;
|
||||
|
||||
namespace actions {
|
||||
|
||||
@@ -74,8 +67,6 @@ class Action {
|
||||
|
||||
virtual ~Action() { }
|
||||
|
||||
virtual std::string evaluate(const std::string &exp,
|
||||
Transaction *transaction);
|
||||
virtual bool evaluate(RuleWithActions *rule, Transaction *transaction);
|
||||
virtual bool evaluate(RuleWithActions *rule, Transaction *transaction,
|
||||
std::shared_ptr<RuleMessage> ruleMessage) {
|
||||
@@ -87,9 +78,9 @@ class Action {
|
||||
|
||||
void set_name_and_payload(const std::string& data) {
|
||||
size_t pos = data.find(":");
|
||||
std::string t = "t:";
|
||||
const char t[] = "t:";
|
||||
|
||||
if (data.compare(0, t.length(), t) == 0) {
|
||||
if (data.compare(0, std::size(t) - 1, t) == 0) {
|
||||
pos = data.find(":", 2);
|
||||
}
|
||||
|
||||
|
@@ -52,7 +52,7 @@ namespace operators {
|
||||
class Operator;
|
||||
}
|
||||
|
||||
using TransformationResult = std::pair<std::shared_ptr<std::string>,
|
||||
using TransformationResult = std::pair<std::string,
|
||||
std::shared_ptr<std::string>>;
|
||||
using TransformationResults = std::list<TransformationResult>;
|
||||
|
||||
|
@@ -119,16 +119,7 @@ class RuleWithActions : public Rule {
|
||||
|
||||
|
||||
void executeTransformations(
|
||||
Transaction *trasn, const std::string &value, TransformationResults &ret);
|
||||
|
||||
inline void executeTransformation(
|
||||
actions::transformations::Transformation *a,
|
||||
std::shared_ptr<std::string> *value,
|
||||
Transaction *trans,
|
||||
TransformationResults *ret,
|
||||
std::string *path,
|
||||
int *nth) const;
|
||||
|
||||
const Transaction *trasn, const std::string &value, TransformationResults &ret);
|
||||
|
||||
void performLogging(Transaction *trans,
|
||||
std::shared_ptr<RuleMessage> ruleMessage,
|
||||
@@ -166,6 +157,14 @@ class RuleWithActions : public Rule {
|
||||
RuleWithActions *m_chainedRuleParent;
|
||||
|
||||
private:
|
||||
inline void executeTransformation(
|
||||
const actions::transformations::Transformation &a,
|
||||
std::string &value,
|
||||
const Transaction *trans,
|
||||
TransformationResults *ret,
|
||||
std::string *path,
|
||||
int *nth) const;
|
||||
|
||||
/* actions */
|
||||
actions::Action *m_disruptiveAction;
|
||||
actions::LogData *m_logData;
|
||||
|
Reference in New Issue
Block a user