Skip to content

Commit 11f85b8

Browse files
authored
Merge pull request #2912 from martinhsv/v2/master
Do not escape special chars in regex pattern with macro
2 parents fb1abae + 2105ed0 commit 11f85b8

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

Diff for: CHANGES

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
DD mmm YYYY - 2.9.x (to be released)
22
-------------------
33

4+
* Do not escape special chars in rx pattern with macro
5+
[Issue #2357 - @marcstern, @martinhsv]
46
* Substitute two equals-equals operators in build
57
[Issue #2883 - @Polynomial-C]
68

Diff for: apache2/re_operators.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* ModSecurity for Apache 2.x, http://www.modsecurity.org/
3-
* Copyright (c) 2004-2022 Trustwave Holdings, Inc. (http://www.trustwave.com/)
3+
* Copyright (c) 2004-2023 Trustwave Holdings, Inc. (http://www.trustwave.com/)
44
*
55
* You may not use this file except in compliance with
66
* the License.  You may obtain a copy of the License at
@@ -1024,7 +1024,7 @@ static int msre_op_rx_execute(modsec_rec *msr, msre_rule *rule, msre_var *var, c
10241024
int matched = 0;
10251025
int rc;
10261026
char *qspos = NULL;
1027-
const char *parm = NULL, *pattern = NULL;
1027+
const char *parm = NULL;
10281028
msc_parm *mparm = NULL;
10291029
#ifdef WITH_PCRE_STUDY
10301030
#ifdef WITH_PCRE_JIT
@@ -1052,17 +1052,17 @@ static int msre_op_rx_execute(modsec_rec *msr, msre_rule *rule, msre_var *var, c
10521052

10531053
expand_macros(msr, re_pattern, rule, msr->mp);
10541054

1055-
pattern = log_escape_re(msr->mp, re_pattern->value);
10561055
if (msr->txcfg->debuglog_level >= 6) {
1057-
msr_log(msr, 6, "Escaping pattern [%s]",pattern);
1056+
char *pattern = log_escape_re(msr->mp, re_pattern->value);
1057+
msr_log(msr, 6, "Expanded-macro pattern [%s]",pattern);
10581058
}
10591059

10601060
#ifdef WITH_PCRE2
10611061
options = PCRE2_DOTALL | PCRE2_DOLLAR_ENDONLY;
10621062
#else
10631063
options = PCRE_DOTALL | PCRE_DOLLAR_ENDONLY;
10641064
#endif
1065-
regex = msc_pregcomp_ex(msr->mp, pattern, options, &errptr, &erroffset, msc_pcre_match_limit, msc_pcre_match_limit_recursion);
1065+
regex = msc_pregcomp_ex(msr->mp, re_pattern->value, options, &errptr, &erroffset, msc_pcre_match_limit, msc_pcre_match_limit_recursion);
10661066
if (regex == NULL) {
10671067
*error_msg = apr_psprintf(msr->mp, "Error compiling pattern (offset %d): %s",
10681068
erroffset, errptr);

0 commit comments

Comments
 (0)