summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2019-01-17 21:06:30 +0100
committerLukas Nykryn <lnykryn@redhat.com>2020-02-06 10:41:56 +0100
commit247d4f826ab189c4dfc4706aaa94782342655218 (patch)
treea070b89e7d1e2c6414528f89b6bf1071debadb32
parent7e9944795e3f0046857379a5f878b365597ed373 (diff)
downloadsystemd-247d4f826ab189c4dfc4706aaa94782342655218.tar.gz
sd-bus: initialize mutex after we allocated the wqueue
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
-rw-r--r--src/libsystemd/sd-bus/sd-bus.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/libsystemd/sd-bus/sd-bus.c b/src/libsystemd/sd-bus/sd-bus.c
index 01060d105c..e49d58137d 100644
--- a/src/libsystemd/sd-bus/sd-bus.c
+++ b/src/libsystemd/sd-bus/sd-bus.c
@@ -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;
}