Skip to content

Commit c0174a7

Browse files
author
Felipe Zimmerle
committed
Revert "Removes a regex optimization added at #1536"
This reverts commit fa7973a.
1 parent e890126 commit c0174a7

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/operators/rx.cc

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,17 @@ bool Rx::evaluate(Transaction *transaction, Rule *rule,
3333
const std::string& input, std::shared_ptr<RuleMessage> ruleMessage) {
3434
SMatch match;
3535
std::list<SMatch> matches;
36-
Regex *re;
36+
Regex * re = m_re;
3737

3838
if (m_param.empty()) {
3939
return true;
4040
}
4141

4242
std::string eparam = MacroExpansion::expand(m_param, transaction);
43-
re = new Regex(eparam);
43+
44+
if (eparam != m_param) {
45+
re = new Regex(eparam);
46+
}
4447

4548
matches = re->searchAll(input);
4649
if (rule && rule->getActionsByName("capture").size() > 0 && transaction) {
@@ -62,7 +65,9 @@ bool Rx::evaluate(Transaction *transaction, Rule *rule,
6265
logOffset(ruleMessage, i.m_offset, i.m_length);
6366
}
6467

65-
delete re;
68+
if (re != m_re) {
69+
delete re;
70+
}
6671

6772
if (matches.size() > 0) {
6873
return true;

src/operators/rx.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,19 @@ class Rx : public Operator {
3737
/** @ingroup ModSecurity_Operator */
3838
Rx(std::string op, std::string param, bool negation)
3939
: Operator(op, param, negation) {
40+
m_re = new Regex(param);
4041
}
4142
Rx(std::string name, std::string param)
4243
: Operator(name, param) {
44+
m_re = new Regex(param);
4345
}
4446
explicit Rx(std::string param)
4547
: Operator("Rx", param) {
48+
m_re = new Regex(param);
4649
}
4750

4851
~Rx() {
52+
delete m_re;
4953
}
5054
bool evaluate(Transaction *transaction, Rule *rule,
5155
const std::string &input) override {
@@ -58,6 +62,9 @@ class Rx : public Operator {
5862
bool evaluate(Transaction *transaction, Rule *rule,
5963
const std::string& input,
6064
std::shared_ptr<RuleMessage> ruleMessage) override;
65+
66+
private:
67+
Regex *m_re;
6168
};
6269

6370

0 commit comments

Comments
 (0)