Adds sanity check to confirm that the rule has an ID and it is not duplicated

This commit is contained in:
Felipe Zimmerle
2015-09-02 10:03:22 -03:00
parent aae8036c0c
commit 035040cd13
85 changed files with 240 additions and 198 deletions

View File

@@ -63,6 +63,24 @@ int Driver::addSecRule(Rule *rule) {
}
}
/*
* Checking if the rule has an ID and also checking if this ID is not used
* by other rule
*/
if (rule->rule_id == 0) {
parserError << "Rules must have an ID." << std::endl;
return false;
}
for (int i = 0; i < ModSecurity::Phases::NUMBER_OF_PHASES; i++) {
std::vector<Rule *> rules = this->rules[i];
for (int j = 0; j < rules.size(); j++) {
if (rules[j]->rule_id == rule->rule_id) {
parserError << "Rule id: " << std::to_string(rule->rule_id) << " is duplicated" << std::endl;
return false;
}
}
}
lastRule = rule;
rules[rule->phase].push_back(rule);
return true;
@@ -83,11 +101,12 @@ int Driver::parse(const std::string &f, const std::string &ref) {
yy::seclang_parser parser(*this);
parser.set_debug_level(trace_parsing);
int res = parser.parse();
scan_end();
if (audit_log->init() == false) {
parserError << "Problems while initializing the audit logs" << std::endl;
return false;
}
scan_end();
return res == 0;
}
@@ -126,6 +145,11 @@ void Driver::error(const yy::location& l, const std::string& m,
parserError << "Line: " << l.end.line << ". ";
parserError << "Column: " << l.end.column << ". ";
}
/*
if (m.empty() == false) {
parserError << " " << m << ".";
}
*/
if (c.empty() == false) {
parserError << c;
}

View File

@@ -324,7 +324,9 @@ expression:
/* variables */ $3,
/* actions */ $8
);
driver.addSecRule(rule);
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

View File

@@ -374,6 +374,7 @@ bool Driver::scan_begin () {
}
void Driver::scan_end () {
yylex_destroy();
BEGIN(INITIAL);
}