diff --git a/src/parser/driver.cc b/src/parser/driver.cc index 77add967..3b0a6950 100644 --- a/src/parser/driver.cc +++ b/src/parser/driver.cc @@ -42,21 +42,13 @@ int Driver::addSecRule(Rule *rule) { return -1; } - int size = this->rules[rule->phase].size(); - - if (size == 0) { - this->rules[rule->phase].push_back(rule); - lastRule = rule; - return true; - } - - - if (lastRule->chained && lastRule->chainedRule == NULL) { + if (lastRule && lastRule->chained && lastRule->chainedRule == NULL) { rule->phase = lastRule->phase; lastRule->chainedRule = rule; return true; } - if (lastRule->chained && lastRule->chainedRule != NULL) { + + if (lastRule && lastRule->chained && lastRule->chainedRule != NULL) { Rule *a = lastRule->chainedRule; while (a->chained && a->chainedRule != NULL) { a = a->chainedRule; @@ -66,6 +58,7 @@ int Driver::addSecRule(Rule *rule) { return true; } } + lastRule = rule; rules[rule->phase].push_back(rule); return true; diff --git a/src/rule.cc b/src/rule.cc index 470b2d00..9710f390 100644 --- a/src/rule.cc +++ b/src/rule.cc @@ -179,13 +179,9 @@ bool Rule::evaluate(Assay *assay) { std::to_string(elapsed_secs) + " seconds"); if (ret) { + bool chainResult = false; assay->debug(4, "Rule returned 1."); - for (Action *a : - this->actions_runtime_pos) { - assay->debug(4, "Running action: " + a->action); - a->evaluate(this, assay); - } if (this->chained && this->chainedRule == NULL) { assay->debug(4, "Rule is marked as chained but there " \ "isn't a subsequent rule."); @@ -203,12 +199,20 @@ bool Rule::evaluate(Assay *assay) { assay->store_variable("MATCHED_VARS:" + v.first, value); assay->store_variable("MATCHED_VARS_NAMES:" + v.first, v.first); - this->chainedRule->evaluate(assay); + chainResult = this->chainedRule->evaluate(assay); assay->update_variable_first("MATCHED_VAR", ""); assay->delete_variable("MATCHED_VARS:" + v.first); assay->delete_variable("MATCHED_VARS_NAMES:" + v.first); assay->delete_variable("MATCHED_VARS_NAMES:" + v.first); } + if (this->chained && chainResult == true || !this->chained) { + for (Action *a : + this->actions_runtime_pos) { + assay->debug(4, "Running action: " + a->action); + a->evaluate(this, assay); + } + } + } else { assay->debug(4, "Rule returned 0."); }