diff --git a/src/parser/seclang-parser.yy b/src/parser/seclang-parser.yy index c00869e3..ca3c7c97 100644 --- a/src/parser/seclang-parser.yy +++ b/src/parser/seclang-parser.yy @@ -248,6 +248,7 @@ using ModSecurity::Variables::Variable; %type *> variables %type var %type act +%type *> actings %printer { yyoutput << $$; } <*>; %% @@ -336,10 +337,24 @@ audit_log: } ; +actings: + QUOTATION_MARK actions SPACE QUOTATION_MARK + { + $$ = $2; + } + | QUOTATION_MARK actions QUOTATION_MARK + { + $$ = $2; + } + | actions + { + $$ = $1; + } + ; + expression: audit_log - | DIRECTIVE SPACE variables SPACE OPERATOR SPACE QUOTATION_MARK actions SPACE QUOTATION_MARK - | DIRECTIVE SPACE variables SPACE OPERATOR SPACE QUOTATION_MARK actions QUOTATION_MARK + | DIRECTIVE SPACE variables SPACE OPERATOR SPACE actings { Operator *op = Operator::instantiate($5); const char *error = NULL; @@ -350,15 +365,14 @@ expression: Rule *rule = new Rule( /* op */ op, /* variables */ $3, - /* actions */ $8 + /* actions */ $7 ); if (driver.addSecRule(rule) == false) { YYERROR; } } - | DIRECTIVE SPACE variables SPACE FREE_TEXT SPACE QUOTATION_MARK actions SPACE QUOTATION_MARK - | DIRECTIVE SPACE variables SPACE FREE_TEXT SPACE QUOTATION_MARK actions QUOTATION_MARK + | DIRECTIVE SPACE variables SPACE FREE_TEXT SPACE actings { Operator *op = Operator::instantiate("\"@rx " + $5 + "\""); const char *error = NULL; @@ -369,7 +383,25 @@ expression: Rule *rule = new Rule( /* op */ op, /* variables */ $3, - /* actions */ $8 + /* actions */ $7 + ); + + if (driver.addSecRule(rule) == false) { + YYERROR; + } + } + | DIRECTIVE SPACE variables SPACE OPERATOR + { + Operator *op = Operator::instantiate("\"@rx " + $5 + "\""); + const char *error = NULL; + if (op->init(&error) == false) { + driver.error(@0, error); + YYERROR; + } + Rule *rule = new Rule( + /* op */ op, + /* variables */ $3, + /* actions */ NULL ); if (driver.addSecRule(rule) == false) { diff --git a/src/rule.cc b/src/rule.cc index 3494f3b3..66aa7ba8 100644 --- a/src/rule.cc +++ b/src/rule.cc @@ -97,18 +97,20 @@ Rule::Rule(Operator *_op, m_secmarker(false), m_marker(""), m_referenceCount(0) { - for (Action *a : *actions) { - if (a->action_kind == Action::ConfigurationKind) { - actions_conf.push_back(a); - a->evaluate(this, NULL); - } else if (a->action_kind == Action::RunTimeBeforeMatchAttemptKind) { - actions_runtime_pre.push_back(a); - } else if (a->action_kind == Action::RunTimeOnlyIfMatchKind) { - actions_runtime_pos.push_back(a); - } else { - std::cout << "General failure, action: " << a->name; - std::cout << " has an unknown type." << std::endl; - delete a; + if (actions != NULL) { + for (Action *a : *actions) { + if (a->action_kind == Action::ConfigurationKind) { + actions_conf.push_back(a); + a->evaluate(this, NULL); + } else if (a->action_kind == Action::RunTimeBeforeMatchAttemptKind) { + actions_runtime_pre.push_back(a); + } else if (a->action_kind == Action::RunTimeOnlyIfMatchKind) { + actions_runtime_pos.push_back(a); + } else { + std::cout << "General failure, action: " << a->name; + std::cout << " has an unknown type." << std::endl; + delete a; + } } } /**