|
21 | 21 |
|
22 | 22 | #include "modsecurity/transaction.h" |
23 | 23 | #include "src/run_time_string.h" |
| 24 | +#include "src/utils/regex.h" |
24 | 25 | #include "src/utils/string.h" |
25 | 26 | #include "src/operators/begins_with.h" |
26 | 27 | #include "src/operators/contains.h" |
@@ -70,6 +71,43 @@ namespace modsecurity { |
70 | 71 | namespace operators { |
71 | 72 |
|
72 | 73 |
|
| 74 | +void Operator::reportRegexCompileError(Transaction *transaction, |
| 75 | + const Utils::Regex &re) { |
| 76 | + if (transaction == nullptr) { |
| 77 | + return; |
| 78 | + } |
| 79 | + |
| 80 | + ms_dbg_a(transaction, 1, "Error with regular expression: \"" + re.pattern + "\""); |
| 81 | + transaction->m_variableMscPcreError.set("1", transaction->m_variableOffset); |
| 82 | + transaction->m_collections.m_tx_collection->storeOrUpdateFirst("MSC_PCRE_ERROR", "1"); |
| 83 | + ms_dbg_a(transaction, 7, "Set TX.MSC_PCRE_ERROR to 1"); |
| 84 | +} |
| 85 | + |
| 86 | + |
| 87 | +void Operator::reportRegexSearchError(Transaction *transaction, |
| 88 | + const Utils::Regex &re, Utils::RegexResult result, |
| 89 | + const std::string &opName) { |
| 90 | + if (transaction == nullptr) { |
| 91 | + return; |
| 92 | + } |
| 93 | + |
| 94 | + transaction->m_variableMscPcreError.set("1", transaction->m_variableOffset); |
| 95 | + transaction->m_collections.m_tx_collection->storeOrUpdateFirst("MSC_PCRE_ERROR", "1"); |
| 96 | + ms_dbg_a(transaction, 7, "Set TX.MSC_PCRE_ERROR to 1"); |
| 97 | + |
| 98 | + const bool match_limit = (result == Utils::RegexResult::ErrorMatchLimit); |
| 99 | + if (match_limit) { |
| 100 | + transaction->m_variableMscPcreLimitsExceeded.set("1", transaction->m_variableOffset); |
| 101 | + transaction->m_collections.m_tx_collection->storeOrUpdateFirst("MSC_PCRE_LIMITS_EXCEEDED", "1"); |
| 102 | + ms_dbg_a(transaction, 7, "Set TX.MSC_PCRE_LIMITS_EXCEEDED to 1"); |
| 103 | + } |
| 104 | + |
| 105 | + ms_dbg_a(transaction, 1, opName + ": regex error '" |
| 106 | + + (match_limit ? "MATCH_LIMIT" : "OTHER") |
| 107 | + + "' for pattern '" + re.pattern + "'"); |
| 108 | +} |
| 109 | + |
| 110 | + |
73 | 111 | bool Operator::evaluateInternal(Transaction *transaction, |
74 | 112 | RuleWithActions *rule, const std::string& a, RuleMessage &ruleMessage) { |
75 | 113 | bool res = evaluate(transaction, rule, a, ruleMessage); |
|
0 commit comments