You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by yl...@apache.org on 2015/02/03 11:42:21 UTC

svn commit: r1656669 - in /httpd/httpd/trunk: CHANGES modules/core/mod_macro.c

Author: ylavic
Date: Tue Feb  3 10:42:21 2015
New Revision: 1656669

URL: http://svn.apache.org/r1656669
Log:
mod_macro: Clear macros before initialization to avoid use-after-free
on startup or restart when the module is linked statically. PR 57525

Submitted by: apache.org tech.futurequest.net
Committed by: Yann Ylavic

Modified:
    httpd/httpd/trunk/CHANGES
    httpd/httpd/trunk/modules/core/mod_macro.c

Modified: httpd/httpd/trunk/CHANGES
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/CHANGES?rev=1656669&r1=1656668&r2=1656669&view=diff
==============================================================================
--- httpd/httpd/trunk/CHANGES [utf-8] (original)
+++ httpd/httpd/trunk/CHANGES [utf-8] Tue Feb  3 10:42:21 2015
@@ -1,6 +1,10 @@
                                                          -*- coding: utf-8 -*-
 Changes with Apache 2.5.0
 
+  *) mod_macro: Clear macros before initialization to avoid use-after-free
+     on startup or restart when the module is linked statically. PR 57525
+     [apache.org tech.futurequest.net, Yann Ylavic]
+
   *) mod_proxy_http: Don't establish or reuse a backend connection before pre-
      fetching the request body, so to minimize the delay between it is supposed
      to be alive and the first bytes sent: this is a best effort to prevent the

Modified: httpd/httpd/trunk/modules/core/mod_macro.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/core/mod_macro.c?rev=1656669&r1=1656668&r2=1656669&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/core/mod_macro.c (original)
+++ httpd/httpd/trunk/modules/core/mod_macro.c Tue Feb  3 10:42:21 2015
@@ -75,14 +75,9 @@ typedef struct
   Macros are kept globally...
   They are not per-server or per-directory entities.
 
-  I would need a hook BEFORE and AFTER configuration processing
-  to initialize and close them properly, but no such thing is exported,
-  although it could be available from within apache.
-
-  I would have such a hook if in server/config.c
-  The "initializer" does not seem to be called before.
-
   note: they are in a temp_pool, and there is a lazy initialization.
+        ap_macros is reset to NULL in pre_config hook to not depend
+        on static vs dynamic configuration.
 
   hash type: (char *) name -> (ap_macro_t *) macro
 */
@@ -914,6 +909,12 @@ static const char *undef_macro(cmd_parms
     return NULL;
 }
 
+static int macro_pre_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp)
+{
+    ap_macros = NULL;
+    return OK;
+}
+
 /************************************************************* EXPORT MODULE */
 
 /*
@@ -932,6 +933,11 @@ static const command_rec macro_cmds[] =
     {NULL}
 };
 
+static void macro_hooks(apr_pool_t *p)
+{
+    ap_hook_pre_config(macro_pre_config, NULL, NULL, APR_HOOK_MIDDLE);
+}
+
 /*
   Module hooks are request-oriented thus it does not suit configuration
   file utils a lot. I haven't found any clean hook to apply something
@@ -949,5 +955,5 @@ AP_DECLARE_MODULE(macro) = {
         NULL,                   /* create per-server config structure */
         NULL,                   /* merge per-server config structures */
         macro_cmds,             /* configuration commands */
-        NULL                    /* register hooks */
+        macro_hooks             /* register hooks */
 };