Skip to content

Commit

Permalink
Removes a regex optimization added at #1536
Browse files Browse the repository at this point in the history
  • Loading branch information
Felipe Zimmerle committed Oct 6, 2017
1 parent 9e9db08 commit fa7973a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 15 deletions.
11 changes: 3 additions & 8 deletions src/operators/rx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,14 @@ bool Rx::evaluate(Transaction *transaction, Rule *rule,
const std::string& input, std::shared_ptr<RuleMessage> ruleMessage) {
SMatch match;
std::list<SMatch> matches;
Regex * re = m_re;
Regex *re;

if (m_param.empty()) {
return true;
}

std::string eparam = MacroExpansion::expand(m_param, transaction);

if (eparam != m_param) {
re = new Regex(eparam);
}
re = new Regex(eparam);

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

if (re != m_re) {
delete re;
}
delete re;

if (matches.size() > 0) {
return true;
Expand Down
7 changes: 0 additions & 7 deletions src/operators/rx.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,15 @@ class Rx : public Operator {
/** @ingroup ModSecurity_Operator */
Rx(std::string op, std::string param, bool negation)
: Operator(op, param, negation) {
m_re = new Regex(param);
}
Rx(std::string name, std::string param)
: Operator(name, param) {
m_re = new Regex(param);
}
explicit Rx(std::string param)
: Operator("Rx", param) {
m_re = new Regex(param);
}

~Rx() {
delete m_re;
}
bool evaluate(Transaction *transaction, Rule *rule,
const std::string &input) override {
Expand All @@ -62,9 +58,6 @@ class Rx : public Operator {
bool evaluate(Transaction *transaction, Rule *rule,
const std::string& input,
std::shared_ptr<RuleMessage> ruleMessage) override;

private:
Regex *m_re;
};


Expand Down

0 comments on commit fa7973a

Please sign in to comment.