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