From d084ab5f2d21c40e2a7b4193a2cfa8211b17ce65 Mon Sep 17 00:00:00 2001 From: Felipe Zimmerle Date: Tue, 29 Sep 2015 12:22:23 -0300 Subject: [PATCH] Fix the "line counting" on parser errors --- src/parser/driver.cc | 6 +++--- src/parser/seclang-scanner.ll | 12 ++++++------ test/benchmark/basic_rules.conf | 1 + 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/parser/driver.cc b/src/parser/driver.cc index 88a846a7..3a5ae3c9 100644 --- a/src/parser/driver.cc +++ b/src/parser/driver.cc @@ -169,11 +169,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 << "."; + parserError << "" << m << " "; } - */ + if (c.empty() == false) { parserError << c; } diff --git a/src/parser/seclang-scanner.ll b/src/parser/seclang-scanner.ll index 9ef6176b..cc095675 100755 --- a/src/parser/seclang-scanner.ll +++ b/src/parser/seclang-scanner.ll @@ -340,12 +340,12 @@ CONFIG_DIR_UNICODE_MAP_FILE (?i:SecUnicodeMapFile) } [\n]+ { driver.loc.back()->lines(yyleng); driver.loc.back()->step(); } -#[ \t]*SecRule[^\\]*\\\n[ \t]* { BEGIN(COMMENT); } -#[ \t]*SecRule[^\\]*\\\r\n[ \t]* { BEGIN(COMMENT); } -#[ \t]*SecAction[^\\]*\\\n[ \t]* { BEGIN(COMMENT); } -#[ \t]*SecAction[^\\]*\\\r\n[ \t]* { BEGIN(COMMENT); } -#.* { /* comment, just ignore. */ } -. { driver.error (*driver.loc.back(), "invalid character", yytext); } +#[ \t]*SecRule[^\\]*\\\n[ \t]* { driver.loc.back()->lines(1); driver.loc.back()->step(); BEGIN(COMMENT); } +#[ \t]*SecRule[^\\]*\\\r\n[ \t]* { driver.loc.back()->lines(1); driver.loc.back()->step(); BEGIN(COMMENT); } +#[ \t]*SecAction[^\\]*\\\n[ \t]* { driver.loc.back()->lines(1); driver.loc.back()->step(); BEGIN(COMMENT); } +#[ \t]*SecAction[^\\]*\\\r\n[ \t]* { driver.loc.back()->lines(1); driver.loc.back()->step(); BEGIN(COMMENT); } +#.* { driver.loc.back()->step(); /* comment, just ignore. */ } +. { driver.error (*driver.loc.back(), "invalid character", yytext); throw yy::seclang_parser::syntax_error(*driver.loc.back(), yytext); } <> { if (driver.ref.size() > 0) { driver.ref.pop_back(); diff --git a/test/benchmark/basic_rules.conf b/test/benchmark/basic_rules.conf index c08e8322..65d9838d 100644 --- a/test/benchmark/basic_rules.conf +++ b/test/benchmark/basic_rules.conf @@ -1 +1,2 @@ + include "owasp-modsecurity-crs-orig/modsecurity_crs_10_setup.conf"