Skip to content

Commit e419b50

Browse files
lightseyFelipe Zimmerle
authored andcommitted
Store temporaries in the request pool for regexes compiled per-request.
The code for testing regexes with embedded Apache variables (rule->re_precomp == 1) during request processing was utilizing the global engine pool for the storage of temporary values. This approach is not threadsafe, retains the temporary variables longer than they are usable, and causes corruption of the global pool's "cleanups" linked-lists when Apache is configured with a threaded MPM.
1 parent 12cefbd commit e419b50

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

apache2/re_operators.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -784,10 +784,10 @@ static int msre_op_validateHash_execute(modsec_rec *msr, msre_rule *rule, msre_v
784784
msr_log(msr, 6, "Escaping pattern [%s]",pattern);
785785
}
786786

787-
regex = msc_pregcomp_ex(rule->ruleset->mp, pattern, PCRE_DOTALL | PCRE_DOLLAR_ENDONLY, &errptr,
787+
regex = msc_pregcomp_ex(msr->mp, pattern, PCRE_DOTALL | PCRE_DOLLAR_ENDONLY, &errptr,
788788
&erroffset, msc_pcre_match_limit, msc_pcre_match_limit_recursion);
789789
if (regex == NULL) {
790-
*error_msg = apr_psprintf(rule->ruleset->mp, "Error compiling pattern (offset %d): %s",
790+
*error_msg = apr_psprintf(msr->mp, "Error compiling pattern (offset %d): %s",
791791
erroffset, errptr);
792792
return 0;
793793
}
@@ -797,7 +797,7 @@ static int msre_op_validateHash_execute(modsec_rec *msr, msre_rule *rule, msre_v
797797
if (msr->txcfg->debuglog_level >= 4) {
798798
rc = msc_fullinfo(regex, PCRE_INFO_JIT, &jit);
799799
if ((rc != 0) || (jit != 1)) {
800-
*error_msg = apr_psprintf(rule->ruleset->mp,
800+
*error_msg = apr_psprintf(msr->mp,
801801
"Rule %pp [id \"%s\"][file \"%s\"][line \"%d\"] - "
802802
"Execution error - "
803803
"Does not support JIT (%d)",
@@ -1018,9 +1018,9 @@ static int msre_op_rx_execute(modsec_rec *msr, msre_rule *rule, msre_var *var, c
10181018
msr_log(msr, 6, "Escaping pattern [%s]",pattern);
10191019
}
10201020

1021-
regex = msc_pregcomp_ex(rule->ruleset->mp, pattern, PCRE_DOTALL | PCRE_DOLLAR_ENDONLY, &errptr, &erroffset, msc_pcre_match_limit, msc_pcre_match_limit_recursion);
1021+
regex = msc_pregcomp_ex(msr->mp, pattern, PCRE_DOTALL | PCRE_DOLLAR_ENDONLY, &errptr, &erroffset, msc_pcre_match_limit, msc_pcre_match_limit_recursion);
10221022
if (regex == NULL) {
1023-
*error_msg = apr_psprintf(rule->ruleset->mp, "Error compiling pattern (offset %d): %s",
1023+
*error_msg = apr_psprintf(msr->mp, "Error compiling pattern (offset %d): %s",
10241024
erroffset, errptr);
10251025
return 0;
10261026
}
@@ -1030,7 +1030,7 @@ static int msre_op_rx_execute(modsec_rec *msr, msre_rule *rule, msre_var *var, c
10301030
if (msr->txcfg->debuglog_level >= 4) {
10311031
rc = msc_fullinfo(regex, PCRE_INFO_JIT, &jit);
10321032
if ((rc != 0) || (jit != 1)) {
1033-
*error_msg = apr_psprintf(rule->ruleset->mp,
1033+
*error_msg = apr_psprintf(msr->mp,
10341034
"Rule %pp [id \"%s\"][file \"%s\"][line \"%d\"] - "
10351035
"Execution error - "
10361036
"Does not support JIT (%d)",

0 commit comments

Comments
 (0)