From 8b4f1bc46c2ea1d35f4ca746706645d8761d949a Mon Sep 17 00:00:00 2001 From: Felipe Zimmerle Date: Fri, 11 Nov 2016 15:03:15 -0300 Subject: [PATCH] Fix rule file inclusion path The inclusion was not taking `*' into consideration, leading the relative configuration inclusion to fail. That was very annoying. --- src/parser/seclang-scanner.ll | 6 ++++-- src/utils/system.cc | 10 ++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/parser/seclang-scanner.ll b/src/parser/seclang-scanner.ll index 89c55369..9b6dceef 100755 --- a/src/parser/seclang-scanner.ll +++ b/src/parser/seclang-scanner.ll @@ -396,7 +396,8 @@ VAR_FREE_TEXT_SPACE_COMMA [^, \t\"]+ {CONFIG_INCLUDE}[ ]{CONFIG_VALUE_PATH} { const char *file = strchr(yytext, ' ') + 1; - for (auto& s: modsecurity::utils::expandEnv(file, 0)) { + std::string fi = modsecurity::utils::find_resource(file, driver.ref.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" ); if (!yyin) { @@ -414,7 +415,8 @@ VAR_FREE_TEXT_SPACE_COMMA [^, \t\"]+ const char *file = strchr(yytext, ' ') + 1; char *f = strdup(file + 1); f[strlen(f)-1] = '\0'; - for (auto& s: modsecurity::utils::expandEnv(f, 0)) { + std::string fi = modsecurity::utils::find_resource(f, driver.ref.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" ); if (!yyin) { diff --git a/src/utils/system.cc b/src/utils/system.cc index 02bcd264..4bb3ef31 100644 --- a/src/utils/system.cc +++ b/src/utils/system.cc @@ -70,6 +70,11 @@ std::string find_resource(const std::string& resource, } delete iss; + // What about `*' ? + if (utils::expandEnv(resource, 0).size() > 1) { + return resource; + } + // Trying the same path of the configuration file. std::string f = get_path(config) + "/" + resource; iss = new std::ifstream(f, std::ios::in); @@ -80,6 +85,11 @@ std::string find_resource(const std::string& resource, } delete iss; + // What about `*' ? + if (utils::expandEnv(f, 0).size() > 1) { + return f; + } + return std::string(""); }