Skip to content

Commit

Permalink
[dbus] Handle missing mode setting gracefully. Fixes MER#1576
Browse files Browse the repository at this point in the history
If usb mode setting is not present in usb-moded.ini and override is not
specified in kernel command line, get_mode_setting() will return null.
The handler for "get_config" D-Bus method call does not check the return
value and using the null value triggers abort from sanity checks at
libdbus. Attempting to pass NULL as string via D-Bus causes abort.

Use MODE_UNDEFINED as fallback in case the setting value is not defined.

Also remove potential memory leaks in the code used for determining the
mode setting value and use correct function for releasing the resulting
dynamically allocated string.

Signed-off-by: Simo Piiroinen <simo.piiroinen@jollamobile.com>
  • Loading branch information
spiiroin committed Apr 29, 2016
1 parent 953d302 commit 1aadb95
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/usb_moded-config.c
Expand Up @@ -310,21 +310,21 @@ static char * get_kcmdline_string(const char *entry)
{
if(!strcmp(entry, NETWORK_IP_KEY))
{
ret = g_strdup(network_tokens[0]);
g_free(ret), ret = g_strdup(network_tokens[0]);
log_debug("Command line ip = %s\n", ret);
}
if(!strcmp(entry, NETWORK_GATEWAY_KEY))
{
/* gateway might be empty, so we do not want to return an empty string */
if(strlen(network_tokens[2]) > 2)
{
ret = g_strdup(network_tokens[2]);
g_free(ret), ret = g_strdup(network_tokens[2]);
log_debug("Command line gateway = %s\n", ret);
}
}
if(!strcmp(entry, NETWORK_NETMASK_KEY))
{
ret = g_strdup(network_tokens[3]);
g_free(ret), ret = g_strdup(network_tokens[3]);
log_debug("Command line netmask = %s\n", ret);
}
}
Expand Down
9 changes: 8 additions & 1 deletion src/usb_moded-dbus.c
Expand Up @@ -304,9 +304,16 @@ static DBusHandlerResult msg_handler(DBusConnection *const connection, DBusMessa
{
char *config = get_mode_setting();

if(!config)
{
/* Config is corrupted or we do not have a mode
* configured, fallback to undefined. */
config = g_strdup(MODE_UNDEFINED);
}

if((reply = dbus_message_new_method_return(msg)))
dbus_message_append_args (reply, DBUS_TYPE_STRING, &config, DBUS_TYPE_INVALID);
free(config);
g_free(config);
}
else if(!strcmp(member, USB_MODE_LIST))
{
Expand Down

0 comments on commit 1aadb95

Please sign in to comment.