From c2d33823f59c2360b1ad2163aa07b4d3165cb8cd Mon Sep 17 00:00:00 2001 From: Felipe Zimmerle Date: Mon, 27 Jul 2015 22:43:45 -0300 Subject: [PATCH] Adds method init to Operator class --- src/operators/operator.h | 3 ++- src/parser/seclang-parser.yy | 8 +++++++- test/unit/unit.cc | 2 ++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/operators/operator.h b/src/operators/operator.h index 822aa161..20fabbcd 100644 --- a/src/operators/operator.h +++ b/src/operators/operator.h @@ -35,11 +35,12 @@ class Operator { param(param), negation(negation) { } - + virtual ~Operator() { } std::string op; std::string param; bool negation; + virtual bool init(const char **error) { return true; } virtual bool evaluate(Assay *assay); virtual bool evaluate(Assay *assay, const std::string &str); static Operator *instantiate(std::string op); diff --git a/src/parser/seclang-parser.yy b/src/parser/seclang-parser.yy index e60a8863..1ada6c61 100644 --- a/src/parser/seclang-parser.yy +++ b/src/parser/seclang-parser.yy @@ -261,8 +261,14 @@ expression: audit_log | DIRECTIVE SPACE variables SPACE OPERATOR SPACE QUOTATION_MARK actions QUOTATION_MARK { + Operator *op = Operator::instantiate($5); + const char *error = NULL; + if (op->init(&error) == false) { + driver.parserError << error; + YYERROR; + } Rule *rule = new Rule( - /* op */ Operator::instantiate($5), + /* op */ op, /* variables */ $3, /* actions */ $8 ); diff --git a/test/unit/unit.cc b/test/unit/unit.cc index e1d0a221..d8955873 100644 --- a/test/unit/unit.cc +++ b/test/unit/unit.cc @@ -54,9 +54,11 @@ void print_help() { void perform_unit_test(UnitTest *t, ModSecurityTestResults* res) { + const char *error = NULL; ModSecurity::operators::Operator *op = ModSecurity::operators::Operator::instantiate("\"@" + t->name + \ " " + t->param + "\""); + op->init(&error); int ret = op->evaluate(NULL, t->input); if (ret != t->ret) {