diff --git a/src/operators/ends_with.cc b/src/operators/ends_with.cc index 444b52e7..212c9bd7 100644 --- a/src/operators/ends_with.cc +++ b/src/operators/ends_with.cc @@ -22,37 +22,21 @@ namespace ModSecurity { namespace operators { -bool EndsWith::evaluate(Assay *assay, - std::string input) { - // Check that the param is not longer than the input - if (this->param.length() > input.length()) { - return 0; + +bool EndsWith::evaluate(Assay *assay, const std::string &input) { + bool ret = false; + if (input.length() >= param.length()) { + ret = (0 == input.compare(input.length() - param.length(), + param.length(), param)); } - // Check that the input != the param - if (this->param == input) { - return 1; + if (negation) { + return !ret; } - // Start at the end of the input minus the size of the input - std::string endString = input.substr(input.length() - \ - (this->param.length()), (this->param.length())); - - // FIXME: We can make this smalle - if (endString == this->param) { - return 1; - } - - return 0; + return ret; } -EndsWith::EndsWith(std::string op, std::string param, - bool negation) - : Operator() { - this->op = op; - this->param = param; -} - } // namespace operators } // namespace ModSecurity diff --git a/src/operators/ends_with.h b/src/operators/ends_with.h index f15263c4..3d7d957f 100644 --- a/src/operators/ends_with.h +++ b/src/operators/ends_with.h @@ -27,8 +27,10 @@ namespace operators { class EndsWith : public Operator { public: /** @ingroup ModSecurity_Operator */ - EndsWith(std::string o, std::string p, bool i); - bool evaluate(Assay *assay, std::string exp); + EndsWith(std::string op, std::string param, bool negation) + : Operator(op, param, negation) { } + + bool evaluate(Assay *assay, const std::string &str) override; }; diff --git a/test/test-cases/secrules-language-tests b/test/test-cases/secrules-language-tests index 93eddeff..55534e69 160000 --- a/test/test-cases/secrules-language-tests +++ b/test/test-cases/secrules-language-tests @@ -1 +1 @@ -Subproject commit 93eddefff48e295179d6884691ecb24c362735be +Subproject commit 55534e6966ebf037db68025eb2b3a14f056cd278