parser: Improves the include error when the file does not exist

This commit is contained in:
Felipe Zimmerle 2016-11-14 10:23:00 -03:00
parent 8b4f1bc46c
commit 4643501507
No known key found for this signature in database
GPG Key ID: E6DFB08CE8B11277

View File

@ -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" );