Le 12/07/2021 à 12:32, [email protected] a écrit :
Author: ylavic
Date: Mon Jul 12 10:32:21 2021
New Revision: 1891477

URL: http://svn.apache.org/viewvc?rev=1891477&view=rev
Log:
mod_proxy: Fix icomplete initialization of BalancerMember(s) from the manager.

Clear the workers created in ap_proxy_sync_balancer(), notably ->local_status
for below ap_proxy_initialize_worker() to initialize all the child structures
like ->cp and ->cp->reslist, avoiding a possible crash when the workers are
used at runtime.

Added:
     httpd/httpd/trunk/changes-entries/ap_proxy_sync_balancer.txt
Modified:
     httpd/httpd/trunk/modules/proxy/proxy_util.c

Added: httpd/httpd/trunk/changes-entries/ap_proxy_sync_balancer.txt
URL: 
http://svn.apache.org/viewvc/httpd/httpd/trunk/changes-entries/ap_proxy_sync_balancer.txt?rev=1891477&view=auto
==============================================================================
--- httpd/httpd/trunk/changes-entries/ap_proxy_sync_balancer.txt (added)
+++ httpd/httpd/trunk/changes-entries/ap_proxy_sync_balancer.txt Mon Jul 12 
10:32:21 2021
@@ -0,0 +1,2 @@
+  *) mod_proxy: Fix icomplete initialization of BalancerMember(s) from the
+     balancer-manager, which can lead to a crash.  [Yann Ylavic]

Modified: httpd/httpd/trunk/modules/proxy/proxy_util.c
URL: 
http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/proxy/proxy_util.c?rev=1891477&r1=1891476&r2=1891477&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/proxy/proxy_util.c (original)
+++ httpd/httpd/trunk/modules/proxy/proxy_util.c Mon Jul 12 10:32:21 2021
@@ -3681,9 +3681,8 @@ PROXY_DECLARE(apr_status_t) ap_proxy_syn
              runtime = apr_array_push(b->workers);
              *runtime = apr_palloc(conf->pool, sizeof(proxy_worker));
              apr_global_mutex_unlock(proxy_mutex);
+            memset(*runtime, 0, sizeof(proxy_worker));
              (*runtime)->hash = shm->hash;
-            (*runtime)->context = NULL;
-            (*runtime)->cp = NULL;
              (*runtime)->balancer = b;
              (*runtime)->s = shm;
  #if APR_HAS_THREADS


Hi,
just wondering if it is safe to array_push+palloc within a mutex and finalize the initialization of this memory outside the mutex?

If this is fine, maybe the palloc could be done outside the mutex too?
If not, maybe pcalloc instead of an explicit memset?


Also, the #if APR_HAS_THREADS block could be removed, tmutex will be NULL'ed by the memset.

just my 2c.

CJ

Reply via email to