daandemeyer / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
4b8c80
From fb04f17617458d2d3d09e0bef29f1255d4d3500c Mon Sep 17 00:00:00 2001
4b8c80
From: Lennart Poettering <lennart@poettering.net>
4b8c80
Date: Thu, 17 Jan 2019 21:06:30 +0100
4b8c80
Subject: [PATCH] sd-bus: initialize mutex after we allocated the wqueue
4b8c80
4b8c80
That way the mutex doesn't have to be destroyed when we exit early due
4b8c80
to OOM.
4b8c80
4b8c80
(cherry picked from commit 2fe9a10d7695c4c3a748969a0d1662c624e50e5e)
4b8c80
Related: CVE-2020-1712
4b8c80
---
4b8c80
 src/libsystemd/sd-bus/sd-bus.c | 4 ++--
4b8c80
 1 file changed, 2 insertions(+), 2 deletions(-)
4b8c80
4b8c80
diff --git a/src/libsystemd/sd-bus/sd-bus.c b/src/libsystemd/sd-bus/sd-bus.c
4b8c80
index 01060d105c..e49d58137d 100644
4b8c80
--- a/src/libsystemd/sd-bus/sd-bus.c
4b8c80
+++ b/src/libsystemd/sd-bus/sd-bus.c
4b8c80
@@ -248,12 +248,12 @@ _public_ int sd_bus_new(sd_bus **ret) {
4b8c80
         b->original_pid = getpid_cached();
4b8c80
         b->n_groups = (size_t) -1;
4b8c80
 
4b8c80
-        assert_se(pthread_mutex_init(&b->memfd_cache_mutex, NULL) == 0);
4b8c80
-
4b8c80
         /* We guarantee that wqueue always has space for at least one entry */
4b8c80
         if (!GREEDY_REALLOC(b->wqueue, b->wqueue_allocated, 1))
4b8c80
                 return -ENOMEM;
4b8c80
 
4b8c80
+        assert_se(pthread_mutex_init(&b->memfd_cache_mutex, NULL) == 0);
4b8c80
+
4b8c80
         *ret = TAKE_PTR(b);
4b8c80
         return 0;
4b8c80
 }