From 1de8d188837e4cbce8894fa7cc1202d48afbcff3 Mon Sep 17 00:00:00 2001 From: Antonio Quartulli Date: Fri, 15 Jun 2018 22:30:27 +0800 Subject: [PATCH] main: don't crash if DBus is not running dbus_init() currently does not check for the g_dbus object being properly initialized and this leads to crashes when dbus is not yet running. Ensure g_dbus is properly initialized and return false otherwise. In this case the caller can understand that something went wrong and stop the initialization procedure. Program received signal SIGSEGV, Segmentation fault. 0x00005555555bc089 in l_dbus_add_service_watch (dbus=0x0, name=0x5555555e5b0a "org.ofono", connect_func=0x5555555aa81e , disconnect_func=0x5555555aa8e6 , user_data=0x0, destroy=0x0) at ell/dbus.c:1621 1621 if (!dbus->name_cache) (gdb) bt name=0x5555555e5b0a "org.ofono", connect_func=0x5555555aa81e , disconnect_func=0x5555555aa8e6 , user_data=0x0, destroy=0x0) at ell/dbus.c:1621 user_data=0x0) at ell/plugin.c:115 function=0x5555555b40fd , user_data=0x0) at ell/queue.c:441 version=0x0) at ell/plugin.c:201 src/plugin.c:82 src/main.c:417 --- src/dbus.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/dbus.c b/src/dbus.c index dfd64fe8..a165954e 100644 --- a/src/dbus.c +++ b/src/dbus.c @@ -214,6 +214,8 @@ struct l_dbus *dbus_get_bus(void) bool dbus_init(bool enable_debug) { g_dbus = l_dbus_new_default(L_DBUS_SYSTEM_BUS); + if (!g_dbus) + return false; if (enable_debug) l_dbus_set_debug(g_dbus, do_debug, "[DBUS] ", NULL);