Skip to content

Commit

Permalink
[usb-moded] Avoid potential crash in the dbus message handling
Browse files Browse the repository at this point in the history
Signed-off-by: Philippe De Swert <philippe.deswert@jollamobile.com>
  • Loading branch information
philippedeswert committed Oct 25, 2013
1 parent eda2a3f commit 37f34a2
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/usb_moded-dbus.c
Expand Up @@ -42,6 +42,7 @@ extern gboolean rescue_mode;

static DBusHandlerResult msg_handler(DBusConnection *const connection, DBusMessage *const msg, gpointer const user_data)
{
const char *mode = NULL;
DBusHandlerResult status = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
DBusMessage *reply = 0;
const char *interface = dbus_message_get_interface(msg);
Expand All @@ -64,7 +65,6 @@ static DBusHandlerResult msg_handler(DBusConnection *const connection, DBusMessa
" </interface>\n"
" </node>\n";


(void)user_data;

if(!interface || !member || !object) goto EXIT;
Expand All @@ -75,11 +75,10 @@ static DBusHandlerResult msg_handler(DBusConnection *const connection, DBusMessa

if(!strcmp(member, USB_MODE_STATE_REQUEST))
{
const char *mode = strdup(get_usb_mode());
mode = strdup(get_usb_mode());

if((reply = dbus_message_new_method_return(msg)))
dbus_message_append_args (reply, DBUS_TYPE_STRING, &mode, DBUS_TYPE_INVALID);
free((void *)mode);
}
else if(!strcmp(member, USB_MODE_STATE_SET))
{
Expand Down Expand Up @@ -119,7 +118,7 @@ static DBusHandlerResult msg_handler(DBusConnection *const connection, DBusMessa
reply = dbus_message_new_error(msg, DBUS_ERROR_INVALID_ARGS, member);
else
{
/* error checking is done when setting the GConf key */
/* error checking is done when setting configuration */
if(!set_mode_setting(config))
{
if((reply = dbus_message_new_method_return(msg)))
Expand Down Expand Up @@ -229,6 +228,9 @@ static DBusHandlerResult msg_handler(DBusConnection *const connection, DBusMessa
dbus_message_unref(reply);
}

if(mode)
free((void *)mode);

return status;
}

Expand Down

0 comments on commit 37f34a2

Please sign in to comment.