b6e473
--- subversion-1.14.1/subversion/libsvn_repos/authz.c
b6e473
+++ subversion-1.14.1/subversion/libsvn_repos/authz.c
b6e473
@@ -130,6 +130,30 @@
b6e473
 static svn_object_pool__t *filtered_pool = NULL;
b6e473
 static svn_atomic_t authz_pool_initialized = FALSE;
b6e473
 
b6e473
+/*
b6e473
+ * Ensure that we will initialize authz again if the pool which
b6e473
+ * our authz caches depend on is cleared.
b6e473
+ *
b6e473
+ * HTTPD may run pre/post config hooks multiple times and clear
b6e473
+ * its global configuration pool which our authz pools depend on.
b6e473
+ * This happens in a non-threaded context during HTTPD's intialization
b6e473
+ * and HTTPD's main loop, so it is safe to reset static variables here.
b6e473
+ * (And any applications which cleared this pool while SVN threads
b6e473
+ * were running would crash no matter what.)
b6e473
+ *
b6e473
+ * See issue #4880, "Use-after-free of object-pools in
b6e473
+ * subversion/libsvn_repos/authz.c when used as httpd module"
b6e473
+ */
b6e473
+static apr_status_t
b6e473
+deinit_authz(void *data)
b6e473
+{
b6e473
+  /* The two object pools run their own cleanup handlers. */
b6e473
+  authz_pool = NULL;
b6e473
+  filtered_pool = NULL;
b6e473
+  authz_pool_initialized = FALSE;
b6e473
+  return APR_SUCCESS;
b6e473
+}
b6e473
+
b6e473
 /* Implements svn_atomic__err_init_func_t. */
b6e473
 static svn_error_t *
b6e473
 synchronized_authz_initialize(void *baton, apr_pool_t *pool)
b6e473
@@ -143,6 +167,7 @@
b6e473
   SVN_ERR(svn_object_pool__create(&authz_pool, multi_threaded, pool));
b6e473
   SVN_ERR(svn_object_pool__create(&filtered_pool, multi_threaded, pool));
b6e473
 
b6e473
+  apr_pool_cleanup_register(pool, NULL, deinit_authz, apr_pool_cleanup_null);
b6e473
   return SVN_NO_ERROR;
b6e473
 }
b6e473