Skip to content

Commit fb020c5

Browse files
author
toubley
committed
filter comment or blank line for pmFromFile operator¼�
1 parent 93a3b7a commit fb020c5

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/operators/pm_from_file.cc

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,23 @@
2525
namespace modsecurity {
2626
namespace operators {
2727

28+
bool PmFromFile::isComment(const std::string &s) {
29+
if (s.size() == 0) {
30+
return true;
31+
}
32+
size_t pos = s.find("#");
33+
if (pos != std::string::npos) {
34+
for (int i = 0; i < pos; i++) {
35+
if (!std::isspace(s[i])) {
36+
return false;
37+
}
38+
}
39+
} else {
40+
return false;
41+
}
42+
43+
return true;
44+
}
2845

2946
bool PmFromFile::init(const std::string &config, std::string *error) {
3047
std::istream *iss;
@@ -50,7 +67,9 @@ bool PmFromFile::init(const std::string &config, std::string *error) {
5067
}
5168

5269
for (std::string line; std::getline(*iss, line); ) {
53-
acmp_add_pattern(m_p, line.c_str(), NULL, NULL, line.length());
70+
if (isComment(line) == false) {
71+
acmp_add_pattern(m_p, line.c_str(), NULL, NULL, line.length());
72+
}
5473
}
5574

5675
while (m_p->is_failtree_done == 0) {

src/operators/pm_from_file.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ class PmFromFile : public Pm {
3636
: Pm(n, std::move(param)) { }
3737

3838
bool init(const std::string &file, std::string *error) override;
39+
40+
bool isComment(const std::string &s);
3941
};
4042

4143

0 commit comments

Comments
 (0)