Avoids to load a directory structure as a rules file

This commit is contained in:
Felipe Zimmerle 2017-05-02 16:42:22 -03:00
parent c97db2f361
commit 0e05b7bb8a
No known key found for this signature in database
GPG Key ID: E6DFB08CE8B11277
3 changed files with 16 additions and 2 deletions

View File

@ -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;
}

View File

@ -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

View File

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