From ab88083159b0380be709c50e336f12a778028d1f Mon Sep 17 00:00:00 2001 From: Felipe Zimmerle Date: Wed, 16 Nov 2016 15:46:09 -0300 Subject: [PATCH] parser: Fix the expanded list inclusion --- src/parser/seclang-scanner.ll | 9 ++++++--- src/utils/system.cc | 4 ++-- src/utils/system.h | 4 ++-- test/optimization/optimization.cc | 4 ++-- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/parser/seclang-scanner.ll b/src/parser/seclang-scanner.ll index 3e932c8a..d529e330 100755 --- a/src/parser/seclang-scanner.ll +++ b/src/parser/seclang-scanner.ll @@ -402,7 +402,9 @@ VAR_FREE_TEXT_SPACE_COMMA [^, \t\"]+ 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::list files = modsecurity::utils::expandEnv(fi, 0); + files.reverse(); + for (auto& s: files) { std::string f = modsecurity::utils::find_resource(s, driver.ref.back()); yyin = fopen(f.c_str(), "r" ); if (!yyin) { @@ -426,7 +428,9 @@ VAR_FREE_TEXT_SPACE_COMMA [^, \t\"]+ 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::list files = modsecurity::utils::expandEnv(fi, 0); + files.reverse(); + for (auto& s: files) { std::string f = modsecurity::utils::find_resource(s, driver.ref.back()); yyin = fopen(f.c_str(), "r" ); if (!yyin) { @@ -437,7 +441,6 @@ VAR_FREE_TEXT_SPACE_COMMA [^, \t\"]+ driver.ref.push_back(f.c_str()); driver.loc.push_back(new yy::location()); yypush_buffer_state(yy_create_buffer( yyin, YY_BUF_SIZE )); - } free(f); } diff --git a/src/utils/system.cc b/src/utils/system.cc index 4bb3ef31..1e07d628 100644 --- a/src/utils/system.cc +++ b/src/utils/system.cc @@ -106,8 +106,8 @@ std::string get_path(const std::string& file) { } -std::vector expandEnv(const std::string& var, int flags) { - std::vector vars; +std::list expandEnv(const std::string& var, int flags) { + std::list vars; wordexp_t p; if (wordexp(var.c_str(), &p, flags) == false) { diff --git a/src/utils/system.h b/src/utils/system.h index 75fce10a..e6366427 100644 --- a/src/utils/system.h +++ b/src/utils/system.h @@ -16,7 +16,7 @@ #include #include #include -#include +#include #include "modsecurity/modsecurity.h" @@ -31,7 +31,7 @@ namespace utils { double cpu_seconds(void); std::string find_resource(const std::string& file, const std::string& param); std::string get_path(const std::string& file); -std::vector expandEnv(const std::string& var, int flags); +std::list expandEnv(const std::string& var, int flags); void createDir(std::string dir, int mode); diff --git a/test/optimization/optimization.cc b/test/optimization/optimization.cc index 6d5860bc..4116d445 100644 --- a/test/optimization/optimization.cc +++ b/test/optimization/optimization.cc @@ -37,12 +37,12 @@ void print_help() { int main(int argc, char **argv) { modsecurity::Rules *modsecRules = new modsecurity::Rules(); - std::vector files; + std::list files; int total = 0; int i = 1; while (i < argc) { - std::vector tfiles = modsecurity::utils::expandEnv( + std::list tfiles = modsecurity::utils::expandEnv( argv[i], 0); for (const auto &file : tfiles) { files.insert(files.begin(), file);