sd-bus: initialize mutex after we allocated the wqueue
authorLennart Poettering <lennart@poettering.net>
Thu, 17 Jan 2019 20:06:30 +0000 (21:06 +0100)
committerLukas Nykryn <lnykryn@redhat.com>
Mon, 3 Feb 2020 10:05:28 +0000 (11:05 +0100)
That way the mutex doesn't have to be destroyed when we exit early due
to OOM.

(cherry picked from commit 2fe9a10d7695c4c3a748969a0d1662c624e50e5e)
Related: CVE-2020-1712

src/libsystemd/sd-bus/sd-bus.c

index 01060d105c1b0cfb372eb6413b5f572cf035ebea..e49d58137dfceb9756153620b12f03e7bda1fbeb 100644 (file)
@@ -248,12 +248,12 @@ _public_ int sd_bus_new(sd_bus **ret) {
         b->original_pid = getpid_cached();
         b->n_groups = (size_t) -1;
 
-        assert_se(pthread_mutex_init(&b->memfd_cache_mutex, NULL) == 0);
-
         /* We guarantee that wqueue always has space for at least one entry */
         if (!GREEDY_REALLOC(b->wqueue, b->wqueue_allocated, 1))
                 return -ENOMEM;
 
+        assert_se(pthread_mutex_init(&b->memfd_cache_mutex, NULL) == 0);
+
         *ret = TAKE_PTR(b);
         return 0;
 }