From dd664aaa88550c545d1c6dfe6ab65ce37377f89b Mon Sep 17 00:00:00 2001 From: Vojtech Trefny Date: Tue, 26 Mar 2024 14:03:34 +0100 Subject: [PATCH 1/2] lvm-dbus: Fix potential segfault in bd_lvm_init --- src/plugins/lvm-dbus.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/plugins/lvm-dbus.c b/src/plugins/lvm-dbus.c index ff9eb24b..58607231 100644 --- a/src/plugins/lvm-dbus.c +++ b/src/plugins/lvm-dbus.c @@ -256,7 +256,7 @@ static gboolean setup_dbus_connection (GError **error) { addr = g_dbus_address_get_for_bus_sync (G_BUS_TYPE_SYSTEM, NULL, error); if (!addr) { - bd_utils_log_format (BD_UTILS_LOG_CRIT, "Failed to get system bus address: %s\n", (*error)->message); + g_prefix_error (error, "Failed to get system bus address: "); return FALSE; } @@ -267,8 +267,14 @@ static gboolean setup_dbus_connection (GError **error) { g_free (addr); - if (!bus || g_dbus_connection_is_closed (bus)) { - bd_utils_log_format (BD_UTILS_LOG_CRIT, "Failed to create a new connection for the system bus: %s\n", (*error)->message); + if (!bus) { + g_prefix_error (error, "Failed to create a new connection for the system bus: "); + return FALSE; + } + + if (g_dbus_connection_is_closed (bus)) { + g_set_error (error, BD_LVM_ERROR, BD_LVM_ERROR_FAIL, + "Connection is closed"); return FALSE; } From e6810f64f49d789099b96d69ae25705c6bdbe7c9 Mon Sep 17 00:00:00 2001 From: Vojtech Trefny Date: Tue, 26 Mar 2024 14:04:27 +0100 Subject: [PATCH 2/2] lvm-dbus: Fix leaking error in bd_lvm_init --- src/plugins/lvm-dbus.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/plugins/lvm-dbus.c b/src/plugins/lvm-dbus.c index 58607231..0e665a72 100644 --- a/src/plugins/lvm-dbus.c +++ b/src/plugins/lvm-dbus.c @@ -342,6 +342,7 @@ gboolean bd_lvm_init (void) { completely rely on it */ if (G_UNLIKELY (!bus) && !setup_dbus_connection (&error)) { bd_utils_log_format (BD_UTILS_LOG_CRIT, "Failed to setup DBus connection: %s", error->message); + g_clear_error (&error); return FALSE; }