From 485c664a420ff3924a24506e78365af1e9c494b6 Mon Sep 17 00:00:00 2001 From: brectanus Date: Tue, 27 Mar 2007 17:13:42 +0000 Subject: [PATCH] Enhance debug log output for capturing to detect all regex/capture mismatches (trac #21). --- CHANGES | 4 ++-- apache2/re_operators.c | 9 ++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/CHANGES b/CHANGES index 1ff92d19..a11ec3ed 100644 --- a/CHANGES +++ b/CHANGES @@ -8,8 +8,8 @@ * Do not log 'allow' action as intercepted in the debug log. -* Warn if a regular expression captures subexpressions, but the - "capture" action was not specified. +* Write debug log messages when "capture" is set, but the regex does not + capture and vice-versa. * Performance improvements in memory management. diff --git a/apache2/re_operators.c b/apache2/re_operators.c index 30fb62aa..2e31e1f4 100644 --- a/apache2/re_operators.c +++ b/apache2/re_operators.c @@ -109,11 +109,14 @@ static int msre_op_rx_execute(modsec_rec *msr, msre_rule *rule, msre_var *var, c capture = apr_table_get(rule->actionset->actions, "capture") ? 1 : 0; /* Warn when the regex captures but "capture" is not set */ - if (msr->txcfg->debuglog_level >= 2) { - int capcount; + if (msr->txcfg->debuglog_level >= 3) { + int capcount = 0; rc = msc_fullinfo(regex, PCRE_INFO_CAPTURECOUNT, &capcount); if ((capture == 0) && (capcount > 0)) { - msr_log(msr, 2, "Warning. regex captures, but \"capture\" action not set."); + msr_log(msr, 4, "Ignoring regex captures since \"capture\" action is not enabled."); + } + if ((capture == 1) && (capcount == 0)) { + msr_log(msr, 3, "Notice. The \"capture\" action is enabled, but the regex does not have explicit captures."); } }