mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-17 01:36:08 +03:00
Revert "Removes a regex optimization added at #1536"
This reverts commit fa7973a4ef99b0d91122d16ffee51744288d037f.
This commit is contained in:
parent
e89012680e
commit
c0174a7ef7
@ -33,14 +33,17 @@ bool Rx::evaluate(Transaction *transaction, Rule *rule,
|
|||||||
const std::string& input, std::shared_ptr<RuleMessage> ruleMessage) {
|
const std::string& input, std::shared_ptr<RuleMessage> ruleMessage) {
|
||||||
SMatch match;
|
SMatch match;
|
||||||
std::list<SMatch> matches;
|
std::list<SMatch> matches;
|
||||||
Regex *re;
|
Regex * re = m_re;
|
||||||
|
|
||||||
if (m_param.empty()) {
|
if (m_param.empty()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string eparam = MacroExpansion::expand(m_param, transaction);
|
std::string eparam = MacroExpansion::expand(m_param, transaction);
|
||||||
|
|
||||||
|
if (eparam != m_param) {
|
||||||
re = new Regex(eparam);
|
re = new Regex(eparam);
|
||||||
|
}
|
||||||
|
|
||||||
matches = re->searchAll(input);
|
matches = re->searchAll(input);
|
||||||
if (rule && rule->getActionsByName("capture").size() > 0 && transaction) {
|
if (rule && rule->getActionsByName("capture").size() > 0 && transaction) {
|
||||||
@ -62,7 +65,9 @@ bool Rx::evaluate(Transaction *transaction, Rule *rule,
|
|||||||
logOffset(ruleMessage, i.m_offset, i.m_length);
|
logOffset(ruleMessage, i.m_offset, i.m_length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (re != m_re) {
|
||||||
delete re;
|
delete re;
|
||||||
|
}
|
||||||
|
|
||||||
if (matches.size() > 0) {
|
if (matches.size() > 0) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -37,15 +37,19 @@ class Rx : public Operator {
|
|||||||
/** @ingroup ModSecurity_Operator */
|
/** @ingroup ModSecurity_Operator */
|
||||||
Rx(std::string op, std::string param, bool negation)
|
Rx(std::string op, std::string param, bool negation)
|
||||||
: Operator(op, param, negation) {
|
: Operator(op, param, negation) {
|
||||||
|
m_re = new Regex(param);
|
||||||
}
|
}
|
||||||
Rx(std::string name, std::string param)
|
Rx(std::string name, std::string param)
|
||||||
: Operator(name, param) {
|
: Operator(name, param) {
|
||||||
|
m_re = new Regex(param);
|
||||||
}
|
}
|
||||||
explicit Rx(std::string param)
|
explicit Rx(std::string param)
|
||||||
: Operator("Rx", param) {
|
: Operator("Rx", param) {
|
||||||
|
m_re = new Regex(param);
|
||||||
}
|
}
|
||||||
|
|
||||||
~Rx() {
|
~Rx() {
|
||||||
|
delete m_re;
|
||||||
}
|
}
|
||||||
bool evaluate(Transaction *transaction, Rule *rule,
|
bool evaluate(Transaction *transaction, Rule *rule,
|
||||||
const std::string &input) override {
|
const std::string &input) override {
|
||||||
@ -58,6 +62,9 @@ class Rx : public Operator {
|
|||||||
bool evaluate(Transaction *transaction, Rule *rule,
|
bool evaluate(Transaction *transaction, Rule *rule,
|
||||||
const std::string& input,
|
const std::string& input,
|
||||||
std::shared_ptr<RuleMessage> ruleMessage) override;
|
std::shared_ptr<RuleMessage> ruleMessage) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
Regex *m_re;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user