mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-14 05:45:59 +03:00
Avoids to load a directory structure as a rules file
This commit is contained in:
parent
c97db2f361
commit
0e05b7bb8a
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user