Adds support to the @endsWith operator

This commit is contained in:
Felipe Zimmerle 2015-08-11 13:41:24 -03:00
parent 577736abb1
commit 209a3db47f
3 changed files with 14 additions and 28 deletions

View File

@ -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

View File

@ -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;
};

@ -1 +1 @@
Subproject commit 93eddefff48e295179d6884691ecb24c362735be
Subproject commit 55534e6966ebf037db68025eb2b3a14f056cd278