Skip to content

Commit d881efe

Browse files
committed
Switch to simpler PCRE error flags
1 parent 5cc77e4 commit d881efe

File tree

11 files changed

+4313
-4312
lines changed

11 files changed

+4313
-4312
lines changed

headers/modsecurity/transaction.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ class TransactionAnchoredVariables {
134134
m_variableInboundDataError(t, "INBOUND_DATA_ERROR"),
135135
m_variableMatchedVar(t, "MATCHED_VAR"),
136136
m_variableMatchedVarName(t, "MATCHED_VAR_NAME"),
137+
m_variableMscPcreErrored(t, "MSC_PCRE_ERRORED"),
138+
m_variableMscPcreLimitsExceeded(t, "MSC_PCRE_LIMITS_EXCEEDED"),
137139
m_variableMultipartBoundaryQuoted(t, "MULTIPART_BOUNDARY_QUOTED"),
138140
m_variableMultipartBoundaryWhiteSpace(t,
139141
"MULTIPART_BOUNDARY_WHITESPACE"),
@@ -184,8 +186,6 @@ class TransactionAnchoredVariables {
184186
m_variableUniqueID(t, "UNIQUE_ID"),
185187
m_variableUrlEncodedError(t, "URLENCODED_ERROR"),
186188
m_variableUserID(t, "USERID"),
187-
m_variableRxError(t, "RX_ERROR"),
188-
m_variableRxErrorRuleID(t, "RX_ERROR_RULE_ID"),
189189
m_variableArgs(t, "ARGS"),
190190
m_variableArgsGet(t, "ARGS_GET"),
191191
m_variableArgsPost(t, "ARGS_POST"),
@@ -221,6 +221,8 @@ class TransactionAnchoredVariables {
221221
AnchoredVariable m_variableInboundDataError;
222222
AnchoredVariable m_variableMatchedVar;
223223
AnchoredVariable m_variableMatchedVarName;
224+
AnchoredVariable m_variableMscPcreErrored;
225+
AnchoredVariable m_variableMscPcreLimitsExceeded;
224226
AnchoredVariable m_variableMultipartBoundaryQuoted;
225227
AnchoredVariable m_variableMultipartBoundaryWhiteSpace;
226228
AnchoredVariable m_variableMultipartCrlfLFLines;
@@ -267,8 +269,6 @@ class TransactionAnchoredVariables {
267269
AnchoredVariable m_variableUniqueID;
268270
AnchoredVariable m_variableUrlEncodedError;
269271
AnchoredVariable m_variableUserID;
270-
AnchoredVariable m_variableRxError;
271-
AnchoredVariable m_variableRxErrorRuleID;
272272

273273
AnchoredSetVariable m_variableArgs;
274274
AnchoredSetVariable m_variableArgsGet;

src/operators/rx.cc

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,21 +68,16 @@ bool Rx::evaluate(Transaction *transaction, RuleWithActions *rule,
6868

6969
// FIXME: DRY regex error reporting. This logic is currently duplicated in other operators.
7070
if (regex_result != Utils::RegexResult::Ok) {
71+
transaction->m_variableMscPcreErrored.set("1", transaction->m_variableOffset);
72+
7173
std::string regex_error_str = "OTHER";
7274
if (regex_result == Utils::RegexResult::ErrorMatchLimit) {
7375
regex_error_str = "MATCH_LIMIT";
76+
transaction->m_variableMscPcreLimitsExceeded.set("1", transaction->m_variableOffset);
7477
}
7578

7679
ms_dbg_a(transaction, 1, "rx: regex error '" + regex_error_str + "' for pattern '" + re->pattern + "'");
7780

78-
// Only expose the first regex error to indicate there is an issue
79-
if (rule && transaction && transaction->m_variableRxError.m_value.empty()) {
80-
transaction->m_variableRxError.set(regex_error_str, transaction->m_variableOffset);
81-
transaction->m_variableRxErrorRuleID.set(
82-
std::to_string(rule->m_ruleId),
83-
transaction->m_variableOffset
84-
);
85-
}
8681

8782
return false;
8883
}

src/operators/rx_global.cc

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,22 +62,16 @@ bool RxGlobal::evaluate(Transaction *transaction, RuleWithActions *rule,
6262

6363
// FIXME: DRY regex error reporting. This logic is currently duplicated in other operators.
6464
if (regex_result != Utils::RegexResult::Ok) {
65+
transaction->m_variableMscPcreErrored.set("1", transaction->m_variableOffset);
66+
6567
std::string regex_error_str = "OTHER";
6668
if (regex_result == Utils::RegexResult::ErrorMatchLimit) {
6769
regex_error_str = "MATCH_LIMIT";
70+
transaction->m_variableMscPcreLimitsExceeded.set("1", transaction->m_variableOffset);
6871
}
6972

7073
ms_dbg_a(transaction, 1, "rxGlobal: regex error '" + regex_error_str + "' for pattern '" + re->pattern + "'");
7174

72-
// Only expose the first regex error to indicate there is an issue
73-
if (rule && transaction && transaction->m_variableRxError.m_value.empty()) {
74-
transaction->m_variableRxError.set(regex_error_str, transaction->m_variableOffset);
75-
transaction->m_variableRxErrorRuleID.set(
76-
std::to_string(rule->m_ruleId),
77-
transaction->m_variableOffset
78-
);
79-
}
80-
8175
return false;
8276
}
8377

0 commit comments

Comments
 (0)