apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bo...@apache.org
Subject svn commit: r783580 - in /apr/apr/trunk: CHANGES dbd/apr_dbd.c dbm/apr_dbm.c util-misc/apu_dso.c
Date Wed, 10 Jun 2009 23:54:00 GMT
Author: bojan
Date: Wed Jun 10 23:54:00 2009
New Revision: 783580

URL: http://svn.apache.org/viewvc?rev=783580&view=rev
Log:
Fix race conditions in initialisation of DBD, DBM and DSO.
For 2.0, this is just a temporary solution, until this is re-engineered.

Modified:
    apr/apr/trunk/CHANGES
    apr/apr/trunk/dbd/apr_dbd.c
    apr/apr/trunk/dbm/apr_dbm.c
    apr/apr/trunk/util-misc/apu_dso.c

Modified: apr/apr/trunk/CHANGES
URL: http://svn.apache.org/viewvc/apr/apr/trunk/CHANGES?rev=783580&r1=783579&r2=783580&view=diff
==============================================================================
--- apr/apr/trunk/CHANGES [utf-8] (original)
+++ apr/apr/trunk/CHANGES [utf-8] Wed Jun 10 23:54:00 2009
@@ -1,6 +1,9 @@
                                                      -*- coding: utf-8 -*-
 Changes for APR 2.0.0
 
+  *) Fix race conditions in initialisation of DBD, DBM and DSO.
+     [Bojan Smojver]
+
   *) SECURITY: CVE-2009-0023 (cve.mitre.org)
      Fix underflow in apr_strmatch_precompile.
      [Matthew Palmer <mpalmer debian.org>]

Modified: apr/apr/trunk/dbd/apr_dbd.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/dbd/apr_dbd.c?rev=783580&r1=783579&r2=783580&view=diff
==============================================================================
--- apr/apr/trunk/dbd/apr_dbd.c (original)
+++ apr/apr/trunk/dbd/apr_dbd.c Wed Jun 10 23:54:00 2009
@@ -26,6 +26,7 @@
 #include "apr_hash.h"
 #include "apr_thread_mutex.h"
 #include "apr_lib.h"
+#include "apr_atomic.h"
 
 #include "apu_internal.h"
 #include "apr_dbd_internal.h"
@@ -33,6 +34,7 @@
 #include "apu_version.h"
 
 static apr_hash_t *drivers = NULL;
+static apr_uint32_t initialised = 0, in_init = 1;
 
 #define CLEANUP_CAST (apr_status_t (*)(void*))
 
@@ -90,7 +92,12 @@
     apr_status_t ret = APR_SUCCESS;
     apr_pool_t *parent;
 
-    if (drivers != NULL) {
+    if (apr_atomic_inc32(&initialised)) {
+        apr_atomic_set32(&initialised, 1); /* prevent wrap-around */
+
+        while (apr_atomic_read32(&in_init)) /* wait until we get fully inited */
+            ;
+
         return APR_SUCCESS;
     }
 
@@ -141,6 +148,8 @@
     apr_pool_cleanup_register(pool, NULL, apr_dbd_term,
                               apr_pool_cleanup_null);
 
+    apr_atomic_dec32(&in_init);
+
     return ret;
 }
 

Modified: apr/apr/trunk/dbm/apr_dbm.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/dbm/apr_dbm.c?rev=783580&r1=783579&r2=783580&view=diff
==============================================================================
--- apr/apr/trunk/dbm/apr_dbm.c (original)
+++ apr/apr/trunk/dbm/apr_dbm.c Wed Jun 10 23:54:00 2009
@@ -24,6 +24,7 @@
 #define APR_WANT_STRFUNC
 #include "apr_want.h"
 #include "apr_general.h"
+#include "apr_atomic.h"
 
 #include "apu_config.h"
 #include "apu.h"
@@ -59,6 +60,7 @@
 #if APR_HAVE_MODULAR_DSO
 
 static apr_hash_t *drivers = NULL;
+static apr_uint32_t initialised = 0, in_init = 1;
 
 static apr_status_t dbm_term(void *ptr)
 {
@@ -117,8 +119,13 @@
     }
     else usertype = 1;
 
-    if (!drivers)
-    {
+    if (apr_atomic_inc32(&initialised)) {
+        apr_atomic_set32(&initialised, 1); /* prevent wrap-around */
+
+        while (apr_atomic_read32(&in_init)) /* wait until we get fully inited */
+            ;
+    }
+    else {
         apr_pool_t *parent;
 
         /* Top level pool scope, need process-scope lifetime */
@@ -133,6 +140,8 @@
 
         apr_pool_cleanup_register(pool, NULL, dbm_term,
                                   apr_pool_cleanup_null);
+
+        apr_atomic_dec32(&in_init);
     }
 
     rv = apu_dso_mutex_lock();

Modified: apr/apr/trunk/util-misc/apu_dso.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/util-misc/apu_dso.c?rev=783580&r1=783579&r2=783580&view=diff
==============================================================================
--- apr/apr/trunk/util-misc/apu_dso.c (original)
+++ apr/apr/trunk/util-misc/apu_dso.c Wed Jun 10 23:54:00 2009
@@ -27,6 +27,7 @@
 #include "apr_hash.h"
 #include "apr_file_io.h"
 #include "apr_env.h"
+#include "apr_atomic.h"
 
 #include "apu_internal.h"
 #include "apu_version.h"
@@ -37,6 +38,7 @@
 static apr_thread_mutex_t* mutex = NULL;
 #endif
 static apr_hash_t *dsos = NULL;
+static apr_uint32_t initialised = 0, in_init = 1;
 
 #if APR_HAS_THREADS
 apr_status_t apu_dso_mutex_lock()
@@ -76,7 +78,12 @@
     apr_pool_t *global;
     apr_pool_t *parent;
 
-    if (dsos != NULL) {
+    if (apr_atomic_inc32(&initialised)) {
+        apr_atomic_set32(&initialised, 1); /* prevent wrap-around */
+
+        while (apr_atomic_read32(&in_init)) /* wait until we get fully inited */
+            ;
+
         return APR_SUCCESS;
     }
 
@@ -94,6 +101,8 @@
     apr_pool_cleanup_register(global, NULL, apu_dso_term,
                               apr_pool_cleanup_null);
 
+    apr_atomic_dec32(&in_init);
+
     return ret;
 }
 



Mime
View raw message