Commit fdc32b06 authored by spiiroin's avatar spiiroin

[dbus] Deal with NULL strings on D-Bus signal broadcast attempts

Corrupted settings, empty lists and other hiccups can lead to usb-moded
attempting to send D-Bus signal with NULL strings - which either leads
to omitting signal sending when checked / crashing when not checked.

To avoid crashing, make umdbus_send_signal_ex() send empty string when
signal with null content is given, and add sufficient checks / diagnostic
logging to umdbus_send_config_signal().

Remove null checks from common_send_hidden_modes_signal() and
common_send_whitelisted_modes_signal() so that NULL set gets equated
with empty set and signal broadcasting is never skipped.
Signed-off-by: spiiroin's avatarSimo Piiroinen <simo.piiroinen@jollamobile.com>
parent 67df6982
...@@ -211,11 +211,8 @@ void common_send_available_modes_signal(void) ...@@ -211,11 +211,8 @@ void common_send_available_modes_signal(void)
void common_send_hidden_modes_signal(void) void common_send_hidden_modes_signal(void)
{ {
gchar *mode_list = config_get_hidden_modes(); gchar *mode_list = config_get_hidden_modes();
if(mode_list) { umdbus_send_hidden_modes_signal(mode_list);
// TODO: cleared list not signaled? g_free(mode_list);
umdbus_send_hidden_modes_signal(mode_list);
g_free(mode_list);
}
} }
/** Send whitelisted modes signal /** Send whitelisted modes signal
...@@ -223,11 +220,8 @@ void common_send_hidden_modes_signal(void) ...@@ -223,11 +220,8 @@ void common_send_hidden_modes_signal(void)
void common_send_whitelisted_modes_signal(void) void common_send_whitelisted_modes_signal(void)
{ {
gchar *mode_list = config_get_mode_whitelist(); gchar *mode_list = config_get_mode_whitelist();
if(mode_list) { umdbus_send_whitelisted_modes_signal(mode_list);
// TODO: cleared list not signaled? g_free(mode_list);
umdbus_send_whitelisted_modes_signal(mode_list);
g_free(mode_list);
}
} }
/* ------------------------------------------------------------------------- * /* ------------------------------------------------------------------------- *
......
...@@ -190,25 +190,41 @@ static const char umdbus_introspect_usbmoded[] = ...@@ -190,25 +190,41 @@ static const char umdbus_introspect_usbmoded[] =
*/ */
static void umdbus_send_config_signal(const char *section, const char *key, const char *value) static void umdbus_send_config_signal(const char *section, const char *key, const char *value)
{ {
log_debug("broadcast signal %s(%s, %s, %s)\n", USB_MODE_CONFIG_SIGNAL_NAME, section, key, value); DBusMessage* msg = 0;
if( !umdbus_service_name_acquired ) if( !section || !key || !value ) {
{ log_err("config notification with NULL %s",
!section ? "section" : !key ? "key" : value);
goto EXIT;
}
if( !umdbus_service_name_acquired ) {
log_err("config notification without service: [%s] %s=%s", log_err("config notification without service: [%s] %s=%s",
section, key, value); section, key, value);
goto EXIT;
} }
else if (umdbus_connection)
{ if( !umdbus_connection ) {
DBusMessage* msg = dbus_message_new_signal(USB_MODE_OBJECT, USB_MODE_INTERFACE, USB_MODE_CONFIG_SIGNAL_NAME); log_err("config notification without connection: [%s] %s=%s",
if (msg) { section, key, value);
dbus_message_append_args(msg, DBUS_TYPE_STRING, &section, goto EXIT;
DBUS_TYPE_STRING, &key,
DBUS_TYPE_STRING, &value,
DBUS_TYPE_INVALID);
dbus_connection_send(umdbus_connection, msg, NULL);
dbus_message_unref(msg);
}
} }
log_debug("broadcast signal %s(%s, %s, %s)\n", USB_MODE_CONFIG_SIGNAL_NAME, section, key, value);
msg = dbus_message_new_signal(USB_MODE_OBJECT, USB_MODE_INTERFACE, USB_MODE_CONFIG_SIGNAL_NAME);
if( !msg )
goto EXIT;
dbus_message_append_args(msg, DBUS_TYPE_STRING, &section,
DBUS_TYPE_STRING, &key,
DBUS_TYPE_STRING, &value,
DBUS_TYPE_INVALID);
dbus_connection_send(umdbus_connection, msg, NULL);
EXIT:
if( msg )
dbus_message_unref(msg);
} }
static DBusHandlerResult umdbus_msg_handler(DBusConnection *const connection, DBusMessage *const msg, gpointer const user_data) static DBusHandlerResult umdbus_msg_handler(DBusConnection *const connection, DBusMessage *const msg, gpointer const user_data)
...@@ -728,6 +744,11 @@ static int umdbus_send_signal_ex(const char *signal_type, const char *content) ...@@ -728,6 +744,11 @@ static int umdbus_send_signal_ex(const char *signal_type, const char *content)
int result = 1; int result = 1;
DBusMessage* msg = 0; DBusMessage* msg = 0;
/* Assume NULL content equals no value / empty list, and that skipping
* signal broadcast is never preferable over sending empty string. */
if( !content )
content = "";
log_debug("broadcast signal %s(%s)\n", signal_type, content); log_debug("broadcast signal %s(%s)\n", signal_type, content);
if( !umdbus_service_name_acquired ) if( !umdbus_service_name_acquired )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment