Avoids copy on the transformation operation

This commit is contained in:
Felipe Zimmerle 2019-02-14 19:46:06 -03:00
parent 8cfb289cea
commit 9c526b3647
No known key found for this signature in database
GPG Key ID: E6DFB08CE8B11277
78 changed files with 121 additions and 87 deletions

View File

@ -57,7 +57,7 @@ class Action {
virtual ~Action() { } virtual ~Action() { }
virtual std::string evaluate(std::string exp, virtual std::string evaluate(const std::string &exp,
Transaction *transaction); Transaction *transaction);
virtual bool evaluate(Rule *rule, Transaction *transaction); virtual bool evaluate(Rule *rule, Transaction *transaction);
virtual bool evaluate(Rule *rule, Transaction *transaction, virtual bool evaluate(Rule *rule, Transaction *transaction,

View File

@ -45,7 +45,7 @@ namespace modsecurity {
namespace actions { namespace actions {
std::string Action::evaluate(std::string value, std::string Action::evaluate(const std::string &value,
Transaction *transaction) { Transaction *transaction) {
return value; return value;
} }

View File

@ -32,7 +32,7 @@ namespace actions {
namespace transformations { namespace transformations {
std::string Base64Decode::evaluate(std::string value, std::string Base64Decode::evaluate(const std::string &value,
Transaction *transaction) { Transaction *transaction) {
std::string ret = Utils::Base64::decode(value); std::string ret = Utils::Base64::decode(value);

View File

@ -32,7 +32,7 @@ class Base64Decode : public Transformation {
public: public:
explicit Base64Decode(const std::string &action) : Transformation(action) { } explicit Base64Decode(const std::string &action) : Transformation(action) { }
std::string evaluate(std::string exp, std::string evaluate(const std::string &exp,
Transaction *transaction) override; Transaction *transaction) override;
}; };

View File

@ -32,7 +32,7 @@ namespace actions {
namespace transformations { namespace transformations {
std::string Base64DecodeExt::evaluate(std::string value, std::string Base64DecodeExt::evaluate(const std::string &value,
Transaction *transaction) { Transaction *transaction) {
std::string ret = Utils::Base64::decode_forgiven(value); std::string ret = Utils::Base64::decode_forgiven(value);

View File

@ -32,7 +32,7 @@ class Base64DecodeExt : public Transformation {
public: public:
explicit Base64DecodeExt(const std::string &action) : Transformation(action) { } explicit Base64DecodeExt(const std::string &action) : Transformation(action) { }
std::string evaluate(std::string exp, std::string evaluate(const std::string &exp,
Transaction *transaction) override; Transaction *transaction) override;
}; };

View File

@ -32,7 +32,7 @@ namespace actions {
namespace transformations { namespace transformations {
std::string Base64Encode::evaluate(std::string value, std::string Base64Encode::evaluate(const std::string &value,
Transaction *transaction) { Transaction *transaction) {
std::string ret = Utils::Base64::encode(value); std::string ret = Utils::Base64::encode(value);

View File

@ -32,7 +32,7 @@ class Base64Encode : public Transformation {
public: public:
explicit Base64Encode(const std::string &action) : Transformation(action) { } explicit Base64Encode(const std::string &action) : Transformation(action) { }
std::string evaluate(std::string exp, std::string evaluate(const std::string &exp,
Transaction *transaction) override; Transaction *transaction) override;
}; };

View File

@ -31,7 +31,7 @@ namespace actions {
namespace transformations { namespace transformations {
std::string CmdLine::evaluate(std::string value, std::string CmdLine::evaluate(const std::string &value,
Transaction *transaction) { Transaction *transaction) {
std::string ret; std::string ret;
int space = 0; int space = 0;

View File

@ -33,7 +33,7 @@ class CmdLine : public Transformation {
explicit CmdLine(const std::string &action) explicit CmdLine(const std::string &action)
: Transformation(action) { } : Transformation(action) { }
std::string evaluate(std::string exp, std::string evaluate(const std::string &exp,
Transaction *transaction) override; Transaction *transaction) override;
}; };

View File

@ -35,7 +35,7 @@ CompressWhitespace::CompressWhitespace(const std::string &action)
this->action_kind = 1; this->action_kind = 1;
} }
std::string CompressWhitespace::evaluate(std::string value, std::string CompressWhitespace::evaluate(const std::string &value,
Transaction *transaction) { Transaction *transaction) {
std::string a; std::string a;

View File

@ -30,8 +30,10 @@ namespace transformations {
class CompressWhitespace : public Transformation { class CompressWhitespace : public Transformation {
public: public:
explicit CompressWhitespace(const std::string &action) ; explicit CompressWhitespace(const std::string &action) ;
std::string evaluate(std::string exp,
std::string evaluate(const std::string &exp,
Transaction *transaction) override; Transaction *transaction) override;
}; };

View File

@ -34,7 +34,7 @@ namespace actions {
namespace transformations { namespace transformations {
std::string CssDecode::evaluate(std::string value, std::string CssDecode::evaluate(const std::string &value,
Transaction *transaction) { Transaction *transaction) {
char *tmp = reinterpret_cast<char *>( char *tmp = reinterpret_cast<char *>(

View File

@ -33,7 +33,7 @@ class CssDecode : public Transformation {
public: public:
explicit CssDecode(const std::string &action) explicit CssDecode(const std::string &action)
: Transformation(action) { } : Transformation(action) { }
std::string evaluate(std::string exp, std::string evaluate(const std::string &exp,
Transaction *transaction) override; Transaction *transaction) override;
static int css_decode_inplace(unsigned char *input, int64_t input_len); static int css_decode_inplace(unsigned char *input, int64_t input_len);

View File

@ -140,7 +140,7 @@ int EscapeSeqDecode::ansi_c_sequences_decode_inplace(unsigned char *input,
} }
std::string EscapeSeqDecode::evaluate(std::string value, std::string EscapeSeqDecode::evaluate(const std::string &value,
Transaction *transaction) { Transaction *transaction) {
unsigned char *tmp = (unsigned char *) malloc(sizeof(char) unsigned char *tmp = (unsigned char *) malloc(sizeof(char)

View File

@ -30,8 +30,10 @@ namespace transformations {
class EscapeSeqDecode : public Transformation { class EscapeSeqDecode : public Transformation {
public: public:
explicit EscapeSeqDecode(const std::string &action) ; explicit EscapeSeqDecode(const std::string &action) ;
std::string evaluate(std::string exp,
std::string evaluate(const std::string &exp,
Transaction *transaction) override; Transaction *transaction) override;
int ansi_c_sequences_decode_inplace(unsigned char *input, int input_len); int ansi_c_sequences_decode_inplace(unsigned char *input, int input_len);
}; };

View File

@ -32,7 +32,7 @@ namespace actions {
namespace transformations { namespace transformations {
std::string HexDecode::evaluate(std::string value, std::string HexDecode::evaluate(const std::string &value,
Transaction *transaction) { Transaction *transaction) {
std::string ret; std::string ret;
unsigned char *input; unsigned char *input;

View File

@ -32,7 +32,7 @@ class HexDecode : public Transformation {
public: public:
explicit HexDecode(const std::string &action) : Transformation(action) { } explicit HexDecode(const std::string &action) : Transformation(action) { }
std::string evaluate(std::string exp, std::string evaluate(const std::string &exp,
Transaction *transaction) override; Transaction *transaction) override;
static int inplace(unsigned char *data, int len); static int inplace(unsigned char *data, int len);

View File

@ -36,7 +36,7 @@ HexEncode::HexEncode(const std::string &action)
this->action_kind = 1; this->action_kind = 1;
} }
std::string HexEncode::evaluate(std::string value, std::string HexEncode::evaluate(const std::string &value,
Transaction *transaction) { Transaction *transaction) {
std::stringstream result; std::stringstream result;

View File

@ -30,8 +30,10 @@ namespace transformations {
class HexEncode : public Transformation { class HexEncode : public Transformation {
public: public:
explicit HexEncode(const std::string &action) ;
std::string evaluate(std::string exp, explicit HexEncode(const std::string &action);
std::string evaluate(const std::string &exp,
Transaction *transaction) override; Transaction *transaction) override;
}; };

View File

@ -33,7 +33,7 @@ namespace actions {
namespace transformations { namespace transformations {
std::string HtmlEntityDecode::evaluate(std::string value, std::string HtmlEntityDecode::evaluate(const std::string &value,
Transaction *transaction) { Transaction *transaction) {
std::string ret; std::string ret;
unsigned char *input; unsigned char *input;

View File

@ -36,7 +36,7 @@ class HtmlEntityDecode : public Transformation {
explicit HtmlEntityDecode(const std::string &action) explicit HtmlEntityDecode(const std::string &action)
: Transformation(action) { } : Transformation(action) { }
std::string evaluate(std::string exp, std::string evaluate(const std::string &exp,
Transaction *transaction) override; Transaction *transaction) override;
static int inplace(unsigned char *input, uint64_t input_len); static int inplace(unsigned char *input, uint64_t input_len);

View File

@ -34,7 +34,7 @@ namespace actions {
namespace transformations { namespace transformations {
std::string JsDecode::evaluate(std::string value, std::string JsDecode::evaluate(const std::string &value,
Transaction *transaction) { Transaction *transaction) {
std::string ret; std::string ret;
unsigned char *input; unsigned char *input;

View File

@ -33,7 +33,7 @@ class JsDecode : public Transformation {
explicit JsDecode(const std::string &action) explicit JsDecode(const std::string &action)
: Transformation(action) { } : Transformation(action) { }
std::string evaluate(std::string exp, std::string evaluate(const std::string &exp,
Transaction *transaction) override; Transaction *transaction) override;
static int inplace(unsigned char *input, uint64_t input_len); static int inplace(unsigned char *input, uint64_t input_len);
}; };

View File

@ -35,7 +35,7 @@ Length::Length(const std::string &action)
this->action_kind = 1; this->action_kind = 1;
} }
std::string Length::evaluate(std::string value, std::string Length::evaluate(const std::string &value,
Transaction *transaction) { Transaction *transaction) {
return std::to_string(value.size()); return std::to_string(value.size());

View File

@ -30,8 +30,10 @@ namespace transformations {
class Length : public Transformation { class Length : public Transformation {
public: public:
explicit Length(const std::string &action) ;
std::string evaluate(std::string exp, explicit Length(const std::string &action);
std::string evaluate(const std::string &exp,
Transaction *transaction) override; Transaction *transaction) override;
}; };

View File

@ -31,9 +31,10 @@ LowerCase::LowerCase(const std::string &a)
: Transformation(a) { : Transformation(a) {
} }
std::string LowerCase::evaluate(std::string value, std::string LowerCase::evaluate(const std::string &val,
Transaction *transaction) { Transaction *transaction) {
std::locale loc; std::locale loc;
std::string value(val);
for (std::string::size_type i=0; i < value.length(); ++i) { for (std::string::size_type i=0; i < value.length(); ++i) {
value[i] = std::tolower(value[i], loc); value[i] = std::tolower(value[i], loc);

View File

@ -32,8 +32,8 @@ namespace transformations {
class LowerCase : public Transformation { class LowerCase : public Transformation {
public: public:
explicit LowerCase(const std::string &action) ; explicit LowerCase(const std::string &action);
std::string evaluate(std::string exp, std::string evaluate(const std::string &exp,
Transaction *transaction) override; Transaction *transaction) override;
}; };

View File

@ -31,9 +31,9 @@ namespace actions {
namespace transformations { namespace transformations {
std::string Md5::evaluate(std::string value, std::string Md5::evaluate(const std::string &value,
Transaction *transaction) { Transaction *transaction) {
std::string ret = Utils::Md5::digest(value); std::string ret = Utils::Md5::digest(value);
return ret; return ret;
} }

View File

@ -32,7 +32,7 @@ class Md5 : public Transformation {
public: public:
explicit Md5(const std::string &action) : Transformation(action) { } explicit Md5(const std::string &action) : Transformation(action) { }
std::string evaluate(std::string exp, std::string evaluate(const std::string &exp,
Transaction *transaction) override; Transaction *transaction) override;
}; };

View File

@ -31,7 +31,7 @@ namespace actions {
namespace transformations { namespace transformations {
std::string None::evaluate(std::string value, std::string None::evaluate(const std::string &value,
Transaction *transaction) { Transaction *transaction) {
return value; return value;
} }

View File

@ -34,7 +34,7 @@ class None : public Transformation {
: Transformation(action) : Transformation(action)
{ m_isNone = true; } { m_isNone = true; }
std::string evaluate(std::string exp, std::string evaluate(const std::string &exp,
Transaction *transaction) override; Transaction *transaction) override;
}; };

View File

@ -37,7 +37,7 @@ NormalisePath::NormalisePath(const std::string &action)
this->action_kind = 1; this->action_kind = 1;
} }
std::string NormalisePath::evaluate(std::string value, std::string NormalisePath::evaluate(const std::string &value,
Transaction *transaction) { Transaction *transaction) {
int changed = 0; int changed = 0;

View File

@ -30,8 +30,10 @@ namespace transformations {
class NormalisePath : public Transformation { class NormalisePath : public Transformation {
public: public:
explicit NormalisePath(const std::string &action) ;
std::string evaluate(std::string exp, explicit NormalisePath(const std::string &action);
std::string evaluate(const std::string &exp,
Transaction *transaction) override; Transaction *transaction) override;
static int normalize_path_inplace(unsigned char *input, int input_len, static int normalize_path_inplace(unsigned char *input, int input_len,

View File

@ -34,7 +34,7 @@ namespace actions {
namespace transformations { namespace transformations {
std::string NormalisePathWin::evaluate(std::string value, std::string NormalisePathWin::evaluate(const std::string &value,
Transaction *transaction) { Transaction *transaction) {
int changed; int changed;

View File

@ -33,7 +33,7 @@ class NormalisePathWin : public Transformation {
explicit NormalisePathWin(const std::string &action) explicit NormalisePathWin(const std::string &action)
: Transformation(action) { } : Transformation(action) { }
std::string evaluate(std::string exp, std::string evaluate(const std::string &exp,
Transaction *transaction) override; Transaction *transaction) override;
}; };

View File

@ -32,7 +32,7 @@ namespace actions {
namespace transformations { namespace transformations {
std::string ParityEven7bit::evaluate(std::string value, std::string ParityEven7bit::evaluate(const std::string &value,
Transaction *transaction) { Transaction *transaction) {
std::string ret; std::string ret;
unsigned char *input; unsigned char *input;

View File

@ -32,7 +32,7 @@ class ParityEven7bit : public Transformation {
public: public:
explicit ParityEven7bit(const std::string &action) : Transformation(action) { } explicit ParityEven7bit(const std::string &action) : Transformation(action) { }
std::string evaluate(std::string exp, Transaction *transaction) override; std::string evaluate(const std::string &exp, Transaction *transaction) override;
static bool inplace(unsigned char *input, uint64_t input_len); static bool inplace(unsigned char *input, uint64_t input_len);
}; };

View File

@ -32,7 +32,7 @@ namespace actions {
namespace transformations { namespace transformations {
std::string ParityOdd7bit::evaluate(std::string value, std::string ParityOdd7bit::evaluate(const std::string &value,
Transaction *transaction) { Transaction *transaction) {
std::string ret; std::string ret;
unsigned char *input; unsigned char *input;

View File

@ -32,7 +32,7 @@ class ParityOdd7bit : public Transformation {
public: public:
explicit ParityOdd7bit(const std::string &action) : Transformation(action) { } explicit ParityOdd7bit(const std::string &action) : Transformation(action) { }
std::string evaluate(std::string exp, Transaction *transaction) override; std::string evaluate(const std::string &exp, Transaction *transaction) override;
static bool inplace(unsigned char *input, uint64_t input_len); static bool inplace(unsigned char *input, uint64_t input_len);
}; };

View File

@ -32,7 +32,7 @@ namespace actions {
namespace transformations { namespace transformations {
std::string ParityZero7bit::evaluate(std::string value, std::string ParityZero7bit::evaluate(const std::string &value,
Transaction *transaction) { Transaction *transaction) {
std::string ret; std::string ret;
unsigned char *input; unsigned char *input;

View File

@ -32,7 +32,7 @@ class ParityZero7bit : public Transformation {
public: public:
explicit ParityZero7bit(const std::string &action) : Transformation(action) { } explicit ParityZero7bit(const std::string &action) : Transformation(action) { }
std::string evaluate(std::string exp, Transaction *transaction) override; std::string evaluate(const std::string &exp, Transaction *transaction) override;
static bool inplace(unsigned char *input, uint64_t input_len); static bool inplace(unsigned char *input, uint64_t input_len);
}; };

View File

@ -32,7 +32,7 @@ namespace actions {
namespace transformations { namespace transformations {
std::string RemoveComments::evaluate(std::string value, std::string RemoveComments::evaluate(const std::string &value,
Transaction *transaction) { Transaction *transaction) {
std::string ret; std::string ret;
unsigned char *input; unsigned char *input;

View File

@ -33,7 +33,7 @@ class RemoveComments : public Transformation {
public: public:
explicit RemoveComments(const std::string &action) : Transformation(action) { } explicit RemoveComments(const std::string &action) : Transformation(action) { }
std::string evaluate(std::string exp, std::string evaluate(const std::string &exp,
Transaction *transaction) override; Transaction *transaction) override;
}; };

View File

@ -35,9 +35,10 @@ RemoveCommentsChar::RemoveCommentsChar(const std::string &action)
this->action_kind = 1; this->action_kind = 1;
} }
std::string RemoveCommentsChar::evaluate(std::string value, std::string RemoveCommentsChar::evaluate(const std::string &val,
Transaction *transaction) { Transaction *transaction) {
int64_t i; int64_t i;
std::string value(val);
i = 0; i = 0;
while (i < value.size()) { while (i < value.size()) {

View File

@ -30,8 +30,9 @@ namespace transformations {
class RemoveCommentsChar : public Transformation { class RemoveCommentsChar : public Transformation {
public: public:
explicit RemoveCommentsChar(const std::string &action) ; explicit RemoveCommentsChar(const std::string &action);
std::string evaluate(std::string exp,
std::string evaluate(const std::string &exp,
Transaction *transaction) override; Transaction *transaction) override;
}; };

View File

@ -33,9 +33,10 @@ namespace actions {
namespace transformations { namespace transformations {
std::string RemoveNulls::evaluate(std::string value, std::string RemoveNulls::evaluate(const std::string &val,
Transaction *transaction) { Transaction *transaction) {
int64_t i; int64_t i;
std::string value(val);
i = 0; i = 0;
while (i < value.size()) { while (i < value.size()) {

View File

@ -33,7 +33,7 @@ class RemoveNulls : public Transformation {
explicit RemoveNulls(const std::string &action) explicit RemoveNulls(const std::string &action)
: Transformation(action) { } : Transformation(action) { }
std::string evaluate(std::string exp, std::string evaluate(const std::string &exp,
Transaction *transaction) override; Transaction *transaction) override;
}; };

View File

@ -36,8 +36,9 @@ RemoveWhitespace::RemoveWhitespace(const std::string &action)
this->action_kind = 1; this->action_kind = 1;
} }
std::string RemoveWhitespace::evaluate(std::string value, std::string RemoveWhitespace::evaluate(const std::string &val,
Transaction *transaction) { Transaction *transaction) {
std::string value(val);
int64_t i = 0; int64_t i = 0;

View File

@ -30,8 +30,9 @@ namespace transformations {
class RemoveWhitespace : public Transformation { class RemoveWhitespace : public Transformation {
public: public:
explicit RemoveWhitespace(const std::string &action) ; explicit RemoveWhitespace(const std::string &action);
std::string evaluate(std::string exp,
std::string evaluate(const std::string &exp,
Transaction *transaction) override; Transaction *transaction) override;
}; };

View File

@ -36,7 +36,7 @@ ReplaceComments::ReplaceComments(const std::string &action)
this->action_kind = 1; this->action_kind = 1;
} }
std::string ReplaceComments::evaluate(std::string value, std::string ReplaceComments::evaluate(const std::string &value,
Transaction *transaction) { Transaction *transaction) {
uint64_t i, j, incomment; uint64_t i, j, incomment;

View File

@ -30,8 +30,10 @@ namespace transformations {
class ReplaceComments : public Transformation { class ReplaceComments : public Transformation {
public: public:
explicit ReplaceComments(const std::string &action) ; explicit ReplaceComments(const std::string &action) ;
std::string evaluate(std::string exp,
std::string evaluate(const std::string &exp,
Transaction *transaction) override; Transaction *transaction) override;
}; };

View File

@ -35,9 +35,10 @@ ReplaceNulls::ReplaceNulls(const std::string &action)
this->action_kind = 1; this->action_kind = 1;
} }
std::string ReplaceNulls::evaluate(std::string value, std::string ReplaceNulls::evaluate(const std::string &val,
Transaction *transaction) { Transaction *transaction) {
int64_t i; int64_t i;
std::string value(val);
i = 0; i = 0;
while (i < value.size()) { while (i < value.size()) {

View File

@ -30,8 +30,10 @@ namespace transformations {
class ReplaceNulls : public Transformation { class ReplaceNulls : public Transformation {
public: public:
explicit ReplaceNulls(const std::string &action) ; explicit ReplaceNulls(const std::string &action) ;
std::string evaluate(std::string exp,
std::string evaluate(const std::string &exp,
Transaction *transaction) override; Transaction *transaction) override;
}; };

View File

@ -36,7 +36,7 @@ Sha1::Sha1(const std::string &action)
this->action_kind = 1; this->action_kind = 1;
} }
std::string Sha1::evaluate(std::string value, std::string Sha1::evaluate(const std::string &value,
Transaction *transaction) { Transaction *transaction) {
return Utils::Sha1::digest(value); return Utils::Sha1::digest(value);

View File

@ -31,7 +31,7 @@ namespace transformations {
class Sha1 : public Transformation { class Sha1 : public Transformation {
public: public:
explicit Sha1(const std::string &action) ; explicit Sha1(const std::string &action) ;
std::string evaluate(std::string exp, std::string evaluate(const std::string &exp,
Transaction *transaction) override; Transaction *transaction) override;
}; };

View File

@ -41,7 +41,7 @@ namespace transformations {
#define ISODIGIT(X) ((X >= '0') && (X <= '7')) #define ISODIGIT(X) ((X >= '0') && (X <= '7'))
#endif #endif
std::string SqlHexDecode::evaluate(std::string value, std::string SqlHexDecode::evaluate(const std::string &value,
Transaction *transaction) { Transaction *transaction) {
std::string ret; std::string ret;
unsigned char *input; unsigned char *input;

View File

@ -32,7 +32,7 @@ class SqlHexDecode : public Transformation {
public: public:
explicit SqlHexDecode(const std::string &action) : Transformation(action) { } explicit SqlHexDecode(const std::string &action) : Transformation(action) { }
std::string evaluate(std::string exp, std::string evaluate(const std::string &exp,
Transaction *transaction) override; Transaction *transaction) override;
static int inplace(unsigned char *data, int len); static int inplace(unsigned char *data, int len);

View File

@ -69,7 +69,7 @@ namespace actions {
namespace transformations { namespace transformations {
std::string Transformation::evaluate(std::string value, std::string Transformation::evaluate(const std::string &value,
Transaction *transaction) { Transaction *transaction) {
return value; return value;
} }

View File

@ -35,7 +35,7 @@ class Transformation : public Action {
explicit Transformation(const std::string& _action, int kind) explicit Transformation(const std::string& _action, int kind)
: Action(_action, kind) { } : Action(_action, kind) { }
std::string evaluate(std::string exp, std::string evaluate(const std::string &exp,
Transaction *transaction) override; Transaction *transaction) override;
static Transformation* instantiate(std::string a); static Transformation* instantiate(std::string a);

View File

@ -57,8 +57,9 @@ Trim::Trim(const std::string &action)
std::string std::string
Trim::evaluate(std::string value, Trim::evaluate(const std::string &val,
Transaction *transaction) { Transaction *transaction) {
std::string value(val);
return *this->trim(&value); return *this->trim(&value);
} }

View File

@ -30,8 +30,10 @@ namespace transformations {
class Trim : public Transformation { class Trim : public Transformation {
public: public:
explicit Trim(const std::string &action) ; explicit Trim(const std::string &action) ;
std::string evaluate(std::string exp,
std::string evaluate(const std::string &exp,
Transaction *transaction) override; Transaction *transaction) override;
std::string *ltrim(std::string *s); std::string *ltrim(std::string *s);

View File

@ -38,8 +38,9 @@ TrimLeft::TrimLeft(const std::string &action)
this->action_kind = 1; this->action_kind = 1;
} }
std::string TrimLeft::evaluate(std::string value, std::string TrimLeft::evaluate(const std::string &val,
Transaction *transaction) { Transaction *transaction) {
std::string value(val);
return *ltrim(&value); return *ltrim(&value);
} }

View File

@ -32,7 +32,8 @@ namespace transformations {
class TrimLeft : public Trim { class TrimLeft : public Trim {
public: public:
explicit TrimLeft(const std::string &action) ; explicit TrimLeft(const std::string &action) ;
std::string evaluate(std::string exp,
std::string evaluate(const std::string &exp,
Transaction *transaction) override; Transaction *transaction) override;
}; };

View File

@ -36,8 +36,9 @@ TrimRight::TrimRight(const std::string &action)
this->action_kind = 1; this->action_kind = 1;
} }
std::string TrimRight::evaluate(std::string value, std::string TrimRight::evaluate(const std::string &val,
Transaction *transaction) { Transaction *transaction) {
std::string value(val);
return *this->rtrim(&value); return *this->rtrim(&value);
} }

View File

@ -32,7 +32,8 @@ namespace transformations {
class TrimRight : public Trim { class TrimRight : public Trim {
public: public:
explicit TrimRight(const std::string &action) ; explicit TrimRight(const std::string &action) ;
std::string evaluate(std::string exp,
std::string evaluate(const std::string &exp,
Transaction *transaction) override; Transaction *transaction) override;
}; };

View File

@ -31,8 +31,9 @@ UpperCase::UpperCase(const std::string &a)
: Transformation(a) { : Transformation(a) {
} }
std::string UpperCase::evaluate(std::string value, std::string UpperCase::evaluate(const std::string &val,
Transaction *transaction) { Transaction *transaction) {
std::string value(val);
std::locale loc; std::locale loc;
for (std::string::size_type i=0; i < value.length(); ++i) { for (std::string::size_type i=0; i < value.length(); ++i) {

View File

@ -33,7 +33,8 @@ namespace transformations {
class UpperCase : public Transformation { class UpperCase : public Transformation {
public: public:
explicit UpperCase(const std::string &action) ; explicit UpperCase(const std::string &action) ;
std::string evaluate(std::string exp,
std::string evaluate(const std::string &exp,
Transaction *transaction) override; Transaction *transaction) override;
}; };

View File

@ -37,7 +37,7 @@ UrlDecode::UrlDecode(const std::string &action)
this->action_kind = 1; this->action_kind = 1;
} }
std::string UrlDecode::evaluate(std::string value, std::string UrlDecode::evaluate(const std::string &value,
Transaction *transaction) { Transaction *transaction) {
unsigned char *val = NULL; unsigned char *val = NULL;
int invalid_count = 0; int invalid_count = 0;

View File

@ -32,8 +32,10 @@ namespace transformations {
class UrlDecode : public Transformation { class UrlDecode : public Transformation {
public: public:
explicit UrlDecode(const std::string &action) ; explicit UrlDecode(const std::string &action) ;
std::string evaluate(std::string exp,
std::string evaluate(const std::string &exp,
Transaction *transaction) override; Transaction *transaction) override;
}; };

View File

@ -38,7 +38,7 @@ namespace actions {
namespace transformations { namespace transformations {
std::string UrlDecodeUni::evaluate(std::string value, std::string UrlDecodeUni::evaluate(const std::string &value,
Transaction *t) { Transaction *t) {
std::string ret; std::string ret;
unsigned char *input; unsigned char *input;

View File

@ -33,7 +33,7 @@ class UrlDecodeUni : public Transformation {
public: public:
explicit UrlDecodeUni(const std::string &action) : Transformation(action) { } explicit UrlDecodeUni(const std::string &action) : Transformation(action) { }
std::string evaluate(std::string exp, Transaction *transaction) override; std::string evaluate(const std::string &exp, Transaction *transaction) override;
static int inplace(unsigned char *input, uint64_t input_len, static int inplace(unsigned char *input, uint64_t input_len,
Transaction *transaction); Transaction *transaction);
}; };

View File

@ -87,7 +87,7 @@ std::string UrlEncode::url_enc(const char *input,
} }
std::string UrlEncode::evaluate(std::string value, std::string UrlEncode::evaluate(const std::string &value,
Transaction *transaction) { Transaction *transaction) {
int changed; int changed;

View File

@ -30,8 +30,10 @@ namespace transformations {
class UrlEncode : public Transformation { class UrlEncode : public Transformation {
public: public:
explicit UrlEncode(const std::string &action) ; explicit UrlEncode(const std::string &action) ;
std::string evaluate(std::string exp,
std::string evaluate(const std::string &exp,
Transaction *transaction) override; Transaction *transaction) override;
std::string url_enc(const char *input, std::string url_enc(const char *input,

View File

@ -33,7 +33,7 @@ namespace actions {
namespace transformations { namespace transformations {
std::string Utf8ToUnicode::evaluate(std::string value, std::string Utf8ToUnicode::evaluate(const std::string &value,
Transaction *transaction) { Transaction *transaction) {
std::string ret; std::string ret;
unsigned char *input; unsigned char *input;

View File

@ -37,7 +37,7 @@ class Utf8ToUnicode : public Transformation {
public: public:
explicit Utf8ToUnicode(const std::string &action) : Transformation(action) { } explicit Utf8ToUnicode(const std::string &action) : Transformation(action) { }
std::string evaluate(std::string exp, std::string evaluate(const std::string &exp,
Transaction *transaction) override; Transaction *transaction) override;
static char *inplace(unsigned char *input, uint64_t input_len, static char *inplace(unsigned char *input, uint64_t input_len,

View File

@ -7,7 +7,7 @@ namespace modsecurity {
namespace Utils { namespace Utils {
std::string Md5::hexdigest(std::string& input) { std::string Md5::hexdigest(const std::string& input) {
unsigned char digest[16]; unsigned char digest[16];
mbedtls_md5(reinterpret_cast<const unsigned char *>(input.c_str()), mbedtls_md5(reinterpret_cast<const unsigned char *>(input.c_str()),
@ -22,7 +22,7 @@ std::string Md5::hexdigest(std::string& input) {
} }
std::string Md5::digest(std::string& input) { std::string Md5::digest(const std::string& input) {
unsigned char output[16]; unsigned char output[16];
std::string ret; std::string ret;

View File

@ -31,8 +31,8 @@ class Md5 {
public: public:
Md5() { } Md5() { }
static std::string hexdigest(std::string& input); static std::string hexdigest(const std::string& input);
static std::string digest(std::string& input); static std::string digest(const std::string& input);
}; };
} // namespace Utils } // namespace Utils