parser: Fix the expanded list inclusion

This commit is contained in:
Felipe Zimmerle 2016-11-16 15:46:09 -03:00
parent c98be42f8f
commit ab88083159
No known key found for this signature in database
GPG Key ID: E6DFB08CE8B11277
4 changed files with 12 additions and 9 deletions

View File

@ -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<std::string> 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<std::string> 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);
}

View File

@ -106,8 +106,8 @@ std::string get_path(const std::string& file) {
}
std::vector<std::string> expandEnv(const std::string& var, int flags) {
std::vector<std::string> vars;
std::list<std::string> expandEnv(const std::string& var, int flags) {
std::list<std::string> vars;
wordexp_t p;
if (wordexp(var.c_str(), &p, flags) == false) {

View File

@ -16,7 +16,7 @@
#include <ctime>
#include <iostream>
#include <string>
#include <vector>
#include <list>
#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<std::string> expandEnv(const std::string& var, int flags);
std::list<std::string> expandEnv(const std::string& var, int flags);
void createDir(std::string dir, int mode);

View File

@ -37,12 +37,12 @@ void print_help() {
int main(int argc, char **argv) {
modsecurity::Rules *modsecRules = new modsecurity::Rules();
std::vector<std::string> files;
std::list<std::string> files;
int total = 0;
int i = 1;
while (i < argc) {
std::vector<std::string> tfiles = modsecurity::utils::expandEnv(
std::list<std::string> tfiles = modsecurity::utils::expandEnv(
argv[i], 0);
for (const auto &file : tfiles) {
files.insert(files.begin(), file);