From ff36010963d1c2f2e6b331aa6d7d7d879e3975f6 Mon Sep 17 00:00:00 2001 From: Eric Covener Date: Wed, 19 Feb 2020 12:26:31 +0000 Subject: [PATCH 2/2] add AP_REG_NO_DEFAULT to allow opt-out of pcre defaults ... and use it in mod_substitute to avoid DOTALL git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.4.x@1874191 13f79535-47bb-0310-9956-ffa450edef68 --- include/ap_mmn.h | 1 + include/ap_regex.h | 4 +++- modules/filters/mod_substitute.c | 6 ++++-- server/util_pcre.c | 4 +++- server/util_regex.c | 3 ++- 5 files changed, 13 insertions(+), 5 deletions(-) diff --git a/include/ap_mmn.h b/include/ap_mmn.h index f5043ef..4c74e56 100644 --- a/include/ap_mmn.h +++ b/include/ap_mmn.h @@ -516,6 +516,7 @@ * 20120211.78 (2.4.34-dev) Add response_field_size to proxy_worker_shared * 20120211.79 (2.4.34-dev) Add AP_GETLINE_NOSPC_EOL flag to http_protocol.h * 20120211.90 (2.4.42-dev) AP_REG_DEFAULT macro in ap_regex.h + * 20120211.92 (2.4.42-dev) AP_REG_NO_DEFAULT macro in ap_regex.h */ #define MODULE_MAGIC_COOKIE 0x41503234UL /* "AP24" */ diff --git a/include/ap_regex.h b/include/ap_regex.h index e651eea..7af2f99 100644 --- a/include/ap_regex.h +++ b/include/ap_regex.h @@ -84,7 +84,9 @@ extern "C" { #define AP_REG_DOLLAR_ENDONLY 0x200 /* '$' matches at end of subject string only */ -#define AP_REG_MATCH "MATCH_" /** suggested prefix for ap_regname */ +#define AP_REG_NO_DEFAULT 0x400 /**< Don't implicitely add AP_REG_DEFAULT options */ + +#define AP_REG_MATCH "MATCH_" /**< suggested prefix for ap_regname */ #define AP_REG_DEFAULT (AP_REG_DOTALL|AP_REG_DOLLAR_ENDONLY) diff --git a/modules/filters/mod_substitute.c b/modules/filters/mod_substitute.c index b7d5296..e976c51 100644 --- a/modules/filters/mod_substitute.c +++ b/modules/filters/mod_substitute.c @@ -667,8 +667,10 @@ static const char *set_pattern(cmd_parms *cmd, void *cfg, const char *line) /* first see if we can compile the regex */ if (!is_pattern) { - r = ap_pregcomp(cmd->pool, from, AP_REG_EXTENDED | - (ignore_case ? AP_REG_ICASE : 0)); + int flags = AP_REG_NO_DEFAULT + | (ap_regcomp_get_default_cflags() & AP_REG_DOLLAR_ENDONLY) + | (ignore_case ? AP_REG_ICASE : 0); + r = ap_pregcomp(cmd->pool, from, flags); if (!r) return "Substitute could not compile regex"; } diff --git a/server/util_pcre.c b/server/util_pcre.c index 74722b4..8819871 100644 --- a/server/util_pcre.c +++ b/server/util_pcre.c @@ -168,7 +168,9 @@ AP_DECLARE(int) ap_regcomp(ap_regex_t * preg, const char *pattern, int cflags) int errcode = 0; int options = PCRE_DUPNAMES; - cflags |= default_cflags; + if ((cflags & AP_REG_NO_DEFAULT) == 0) + cflags |= default_cflags; + if ((cflags & AP_REG_ICASE) != 0) options |= PCRE_CASELESS; if ((cflags & AP_REG_NEWLINE) != 0) diff --git a/server/util_regex.c b/server/util_regex.c index 2a30d68..5405f8d 100644 --- a/server/util_regex.c +++ b/server/util_regex.c @@ -94,6 +94,7 @@ AP_DECLARE(ap_rxplus_t*) ap_rxplus_compile(apr_pool_t *pool, } /* anything after the current delimiter is flags */ + ret->flags = ap_regcomp_get_default_cflags() & AP_REG_DOLLAR_ENDONLY; while (*++endp) { switch (*endp) { case 'i': ret->flags |= AP_REG_ICASE; break; @@ -106,7 +107,7 @@ AP_DECLARE(ap_rxplus_t*) ap_rxplus_compile(apr_pool_t *pool, default: break; /* we should probably be stricter here */ } } - if (ap_regcomp(&ret->rx, rxstr, ret->flags) == 0) { + if (ap_regcomp(&ret->rx, rxstr, AP_REG_NO_DEFAULT | ret->flags) == 0) { apr_pool_cleanup_register(pool, &ret->rx, rxplus_cleanup, apr_pool_cleanup_null); } -- 1.8.3.1