From 5a040a6bd0d8d85f447a93e11d704665c84c39c5 Mon Sep 17 00:00:00 2001 From: Jim Jagielski Date: Tue, 6 Oct 2015 12:40:06 +0000 Subject: [PATCH] Merge r1684900, r1687539, r1687680, r1688331, r1688339, r1688340, r1688341, r1688343, r1697013, r1697015 from trunk: mod_substitute: Fix configuraton merge order. PR 57641 [Marc.Stern] mod_substitute: follow up r1684900. Introduce the SubstituteInheritBefore directive to configure the merge order. This allows to preserve 2.4 and earlier behaviour. mod_substitute: follow up to r1687539. Use tristate single inherit_before variable instead of two, according to wrowe's advices. mod_substitute: follow up to r1687680. Fix dir config merger 'over'-write, thanks Bill (again). Very difficult to read, and therefore was wrong. Assert that the SubstituteInheritBefore option was explicitly toggled, and do not default in 2.x to this legacy behavior. Optimize in all cases that the members are all explicitly initialized. Useful for 2.2 and 2.4, but trunk will require the subsequent patch. Increase legibility of the max_line_length behavior, and adjust for the requirement that all members are initialized explicitly due to the previous patch. Net -8 LoC, my usual specialty. This didn't need to be reinvented; please use established helpers. mod_substitute: follow up r1688339. SubstituteInheritBefore is the default in 2.5.x but wasn't for ealier versions. mod_substitute: follow up r1697013. Update the doc. Submitted by: niq, ylavic, ylavic, ylavic, wrowe, wrowe, wrowe, wrowe, ylavic, ylavic Reviewed/backported by: jim git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.4.x@1707039 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES | 4 ++++ STATUS | 13 ----------- docs/manual/mod/mod_substitute.xml | 21 ++++++++++++++++++ modules/filters/mod_substitute.c | 35 ++++++++++++++++++++++++------ 4 files changed, 53 insertions(+), 20 deletions(-) diff --git a/CHANGES b/CHANGES index 288b465912..40e8325ab3 100644 --- a/CHANGES +++ b/CHANGES @@ -2,6 +2,10 @@ Changes with Apache 2.4.17 + *) mod_substitute: Allow to configure the patterns merge order with the new + SubstituteInheritBefore on|off directive. PR 57641 + [Marc.Stern , Yann Ylavic, William Rowe] + *) mod_proxy: Fix ProxySourceAddress binding failure with AH00938. PR 56687. [Arne de Bruijn diff --git a/STATUS b/STATUS index c2741412fb..d9a86a9906 100644 --- a/STATUS +++ b/STATUS @@ -110,19 +110,6 @@ RELEASE SHOWSTOPPERS: PATCHES ACCEPTED TO BACKPORT FROM TRUNK: [ start all new proposals below, under PATCHES PROPOSED. ] - * mod_substitute: Configure patterns merge order. PR 57641 - trunk patch: http://svn.apache.org/r1684900 - http://svn.apache.org/r1687539 - http://svn.apache.org/r1687680 - http://svn.apache.org/r1688331 - http://svn.apache.org/r1688339 - http://svn.apache.org/r1688340 - http://svn.apache.org/r1688341 - http://svn.apache.org/r1688343 - http://svn.apache.org/r1697013 - http://svn.apache.org/r1697015 - 2.4.x patch: http://people.apache.org/~ylavic/httpd-2.4.x-SubstituteInheritBefore-v6.patch - +1: ylavic, wrowe, rjung PATCHES PROPOSED TO BACKPORT FROM TRUNK: diff --git a/docs/manual/mod/mod_substitute.xml b/docs/manual/mod/mod_substitute.xml index 3eb5ed8afe..9475702101 100644 --- a/docs/manual/mod/mod_substitute.xml +++ b/docs/manual/mod/mod_substitute.xml @@ -163,4 +163,25 @@ Substitute "s|http://internal.blog.example.com/|http://www.example.com/blog/|i" + +SubstituteInheritBefore +Change the merge order of inherited patterns +SubstituteInheritBefore on|off +SubstituteInheritBefore off +directory +.htaccess +FileInfo +Available in httpd 2.4.17 and later + + +

Whether to apply the inherited Substitute + patterns first (on), or after the ones of the current + context (off). + SubstituteInheritBefore is itself inherited, + hence contexts that inherit it (those that don't specify their own + SubstituteInheritBefore value) will apply the + closest defined merge order. + + + diff --git a/modules/filters/mod_substitute.c b/modules/filters/mod_substitute.c index 9326348c52..59f5bf3e32 100644 --- a/modules/filters/mod_substitute.c +++ b/modules/filters/mod_substitute.c @@ -57,6 +57,7 @@ typedef struct { apr_array_header_t *patterns; apr_size_t max_line_length; int max_line_length_set; + int inherit_before; } subst_dir_conf; typedef struct { @@ -70,26 +71,43 @@ typedef struct { static void *create_substitute_dcfg(apr_pool_t *p, char *d) { subst_dir_conf *dcfg = - (subst_dir_conf *) apr_pcalloc(p, sizeof(subst_dir_conf)); + (subst_dir_conf *) apr_palloc(p, sizeof(subst_dir_conf)); dcfg->patterns = apr_array_make(p, 10, sizeof(subst_pattern_t)); dcfg->max_line_length = AP_SUBST_MAX_LINE_LENGTH; + dcfg->max_line_length_set = 0; + dcfg->inherit_before = -1; return dcfg; } static void *merge_substitute_dcfg(apr_pool_t *p, void *basev, void *overv) { subst_dir_conf *a = - (subst_dir_conf *) apr_pcalloc(p, sizeof(subst_dir_conf)); + (subst_dir_conf *) apr_palloc(p, sizeof(subst_dir_conf)); subst_dir_conf *base = (subst_dir_conf *) basev; subst_dir_conf *over = (subst_dir_conf *) overv; - a->patterns = apr_array_append(p, over->patterns, - base->patterns); + a->inherit_before = (over->inherit_before != -1) + ? over->inherit_before + : base->inherit_before; + /* SubstituteInheritBefore wasn't the default behavior until 2.5.x, + * and may be re-disabled as desired; the original default behavior + * was to apply inherited subst patterns after locally scoped patterns. + * In later 2.2 and 2.4 versions, SubstituteInheritBefore may be toggled + * 'on' to follow the corrected/expected behavior, without violating POLS. + */ + if (a->inherit_before == 1) { + a->patterns = apr_array_append(p, base->patterns, + over->patterns); + } + else { + a->patterns = apr_array_append(p, over->patterns, + base->patterns); + } a->max_line_length = over->max_line_length_set ? - over->max_line_length : base->max_line_length; - a->max_line_length_set = over->max_line_length_set ? - over->max_line_length_set : base->max_line_length_set; + over->max_line_length : base->max_line_length; + a->max_line_length_set = over->max_line_length_set + | base->max_line_length_set; return a; } @@ -695,6 +713,9 @@ static const command_rec substitute_cmds[] = { "Pattern to filter the response content (s/foo/bar/[inf])"), AP_INIT_TAKE1("SubstituteMaxLineLength", set_max_line_length, NULL, OR_FILEINFO, "Maximum line length"), + AP_INIT_FLAG("SubstituteInheritBefore", ap_set_flag_slot, + (void *)APR_OFFSETOF(subst_dir_conf, inherit_before), OR_FILEINFO, + "Apply inherited patterns before those of the current context"), {NULL} }; -- 2.50.1