Skip to content

Commit 59531be

Browse files
authored
Merge pull request #2723 from martinhsv/v3/master
Add DebugLog message for bad pattern in rx operator
2 parents ced56c5 + 1aa7616 commit 59531be

File tree

5 files changed

+54
-0
lines changed

5 files changed

+54
-0
lines changed

CHANGES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
v3.x.y - YYYY-MMM-DD (to be released)
22
-------------------------------------
33

4+
- Add DebugLog message for bad pattern in rx operator
5+
[Issue #2722 - @martinhsv]
46
- Support PCRE2
57
[Issue #2668 - @martinhsv]
68
- Support SecRequestBodyNoFilesLimit

src/operators/rx.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ bool Rx::evaluate(Transaction *transaction, RuleWithActions *rule,
5252
}
5353

5454
std::vector<Utils::SMatchCapture> captures;
55+
if (re->hasError()) {
56+
ms_dbg_a(transaction, 3, "Error with regular expression: \"" + re->pattern + "\"");
57+
return false;
58+
}
5559
re->searchOneMatch(input, captures);
5660

5761
if (rule && rule->hasCaptureAction() && transaction) {

src/utils/regex.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ Regex::Regex(const std::string& pattern_, bool ignoreCase)
7575
pcre2_options, &errornumber, &erroroffset, NULL);
7676
if (m_pc != NULL) {
7777
m_match_data = pcre2_match_data_create_from_pattern(m_pc, NULL);
78+
if (m_match_data == NULL) {
79+
m_pc = NULL;
80+
}
7881
}
7982
#else
8083
const char *errptr = NULL;

src/utils/regex.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ class Regex {
7272
Regex(const Regex&) = delete;
7373
Regex& operator=(const Regex&) = delete;
7474

75+
bool hasError() const {
76+
return (m_pc == NULL);
77+
}
7578
std::list<SMatch> searchAll(const std::string& s) const;
7679
bool searchOneMatch(const std::string& s, std::vector<SMatchCapture>& captures) const;
7780
bool searchGlobal(const std::string& s, std::vector<SMatchCapture>& captures) const;

test/test-cases/regression/operator-rx.json

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,47 @@
8585
"SecRuleEngine On",
8686
"SecRule REQUEST_HEADERS:Content-Length \"!^0$\" \"id:1,phase:2,pass,t:trim,block\""
8787
]
88+
},
89+
{
90+
"enabled":1,
91+
"version_min":300000,
92+
"title":"Testing Operator :: @rx with non-compiling pattern",
93+
"client":{
94+
"ip":"200.249.12.31",
95+
"port":123
96+
},
97+
"server":{
98+
"ip":"200.249.12.31",
99+
"port":80
100+
},
101+
"request":{
102+
"headers":{
103+
"Host":"localhost",
104+
"User-Agent":"curl/7.38.0",
105+
"Accept":"*/*",
106+
"Content-Length": "27",
107+
"Content-Type": "application/x-www-form-urlencoded"
108+
},
109+
"uri":"/",
110+
"method":"HEAD",
111+
"body": [ ]
112+
},
113+
"response":{
114+
"headers":{
115+
"Date":"Mon, 13 Jul 2015 20:02:41 GMT",
116+
"Last-Modified":"Sun, 26 Oct 2014 22:33:37 GMT",
117+
"Content-Type":"text/html"
118+
},
119+
"body":[
120+
"no need."
121+
]
122+
},
123+
"expected":{
124+
"debug_log":"Error with regular expression"
125+
},
126+
"rules":[
127+
"SecRuleEngine On",
128+
"SecRule REQUEST_HEADERS:Content-Type \"@rx a(b\" \"id:1,phase:2,pass,t:trim,block\""
129+
]
88130
}
89131
]

0 commit comments

Comments
 (0)