uid_wrapper: Fix race condition - uwrap_init.
authorRobin Hack <hack.robin@gmail.com>
Fri, 23 Jan 2015 14:12:43 +0000 (15:12 +0100)
committerAndreas Schneider <asn@cryptomilk.org>
Wed, 28 Jan 2015 16:17:07 +0000 (17:17 +0100)
Patch moves uwrap_id_mutex before if (uwrap.initialised) statement
which can be passed by concurrent threads.

Signed-off-by: Robin Hack <hack.robin@gmail.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
lib/uid_wrapper/uid_wrapper.c

index 772dc93616647a7993bb2e8f125ba70fedbaf620..578977dadc1c14bc67a2490f6b569946b12ef676 100644 (file)
@@ -575,17 +575,16 @@ static void uwrap_init(void)
        const char *env = getenv("UID_WRAPPER");
        pthread_t tid = pthread_self();
 
-
-
+       UWRAP_LOCK(uwrap_id);
        if (uwrap.initialised) {
                struct uwrap_thread *id = uwrap_tls_id;
                int rc;
 
                if (id != NULL) {
+                       UWRAP_UNLOCK(uwrap_id);
                        return;
                }
 
-               UWRAP_LOCK(uwrap_id);
                id = find_uwrap_id(tid);
                if (id == NULL) {
                        rc = uwrap_new_id(tid, true);
@@ -605,8 +604,6 @@ static void uwrap_init(void)
 
        UWRAP_LOG(UWRAP_LOG_DEBUG, "Initialize uid_wrapper");
 
-       UWRAP_LOCK(uwrap_id);
-
        uwrap.initialised = true;
        uwrap.enabled = false;