From 46435015070603e2488e2e0e01753a4a40c0489f Mon Sep 17 00:00:00 2001 From: Felipe Zimmerle Date: Mon, 14 Nov 2016 10:23:00 -0300 Subject: [PATCH] parser: Improves the include error when the file does not exist --- src/parser/seclang-scanner.ll | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/parser/seclang-scanner.ll b/src/parser/seclang-scanner.ll index 9b6dceef..3e932c8a 100755 --- a/src/parser/seclang-scanner.ll +++ b/src/parser/seclang-scanner.ll @@ -397,6 +397,11 @@ VAR_FREE_TEXT_SPACE_COMMA [^, \t\"]+ {CONFIG_INCLUDE}[ ]{CONFIG_VALUE_PATH} { const char *file = strchr(yytext, ' ') + 1; std::string fi = modsecurity::utils::find_resource(file, driver.ref.back()); + if (fi.empty() == true) { + BEGIN(INITIAL); + driver.error (*driver.loc.back(), "", file + std::string(": Not able to open file.")); + throw p::syntax_error(*driver.loc.back(), ""); + } for (auto& s: modsecurity::utils::expandEnv(fi, 0)) { std::string f = modsecurity::utils::find_resource(s, driver.ref.back()); yyin = fopen(f.c_str(), "r" ); @@ -416,6 +421,11 @@ VAR_FREE_TEXT_SPACE_COMMA [^, \t\"]+ char *f = strdup(file + 1); f[strlen(f)-1] = '\0'; std::string fi = modsecurity::utils::find_resource(f, driver.ref.back()); + if (fi.empty() == true) { + BEGIN(INITIAL); + driver.error (*driver.loc.back(), "", file + std::string(": Not able to open file.")); + throw p::syntax_error(*driver.loc.back(), ""); + } for (auto& s: modsecurity::utils::expandEnv(fi, 0)) { std::string f = modsecurity::utils::find_resource(s, driver.ref.back()); yyin = fopen(f.c_str(), "r" );