mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-09-30 19:47:47 +03:00
filter comment or blank line for pmFromFile operator
This commit is contained in:
@@ -25,6 +25,23 @@
|
|||||||
namespace modsecurity {
|
namespace modsecurity {
|
||||||
namespace operators {
|
namespace operators {
|
||||||
|
|
||||||
|
bool PmFromFile::isComment(const std::string &s) {
|
||||||
|
if (s.size() == 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
size_t pos = s.find("#");
|
||||||
|
if (pos != std::string::npos) {
|
||||||
|
for (int i = 0; i < pos; i++) {
|
||||||
|
if (!std::isspace(s[i])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool PmFromFile::init(const std::string &config, std::string *error) {
|
bool PmFromFile::init(const std::string &config, std::string *error) {
|
||||||
std::istream *iss;
|
std::istream *iss;
|
||||||
@@ -50,7 +67,9 @@ bool PmFromFile::init(const std::string &config, std::string *error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (std::string line; std::getline(*iss, line); ) {
|
for (std::string line; std::getline(*iss, line); ) {
|
||||||
acmp_add_pattern(m_p, line.c_str(), NULL, NULL, line.length());
|
if (isComment(line) == false) {
|
||||||
|
acmp_add_pattern(m_p, line.c_str(), NULL, NULL, line.length());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while (m_p->is_failtree_done == 0) {
|
while (m_p->is_failtree_done == 0) {
|
||||||
|
@@ -36,6 +36,8 @@ class PmFromFile : public Pm {
|
|||||||
: Pm(n, std::move(param)) { }
|
: Pm(n, std::move(param)) { }
|
||||||
|
|
||||||
bool init(const std::string &file, std::string *error) override;
|
bool init(const std::string &file, std::string *error) override;
|
||||||
|
|
||||||
|
bool isComment(const std::string &s);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user