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