diff --git a/src/parser/driver.cc b/src/parser/driver.cc index f6188edd..2fe9ba35 100644 --- a/src/parser/driver.cc +++ b/src/parser/driver.cc @@ -157,7 +157,7 @@ int Driver::parseFile(const std::string &f) { std::ifstream t(f); std::string str; - if (t.is_open() == false) { + if (utils::isFile(f) == false) { m_parserError << "Failed to open the file: " << f << std::endl; return false; } diff --git a/src/utils/system.cc b/src/utils/system.cc index 2eeef388..2898edcc 100644 --- a/src/utils/system.cc +++ b/src/utils/system.cc @@ -144,5 +144,19 @@ bool createDir(std::string dir, int mode, std::string *error) { } +bool isFile(std::string f) { + struct stat fileInfo; + FILE *fp = fopen(f.c_str(), "r"); + fstat(fileno(fp), &fileInfo); + if (!S_ISREG(fileInfo.st_mode)) { + fclose(fp); + return false; + } + fclose(fp); + + return true; +} + + } // namespace utils } // namespace modsecurity diff --git a/src/utils/system.h b/src/utils/system.h index e31ea932..04ef35a9 100644 --- a/src/utils/system.h +++ b/src/utils/system.h @@ -34,7 +34,7 @@ std::string find_resource(const std::string& file, const std::string& param, std::string get_path(const std::string& file); std::list expandEnv(const std::string& var, int flags); bool createDir(std::string dir, int mode, std::string *error); - +bool isFile(std::string f); } // namespace utils } // namespace modsecurity