Commit 67df6982 authored by spiiroin's avatar spiiroin

[config] Never return NULL mode setting

If usb-moded configuration is corrupted, it can lead to segfaults as the
return value from config_get_mode_setting() is not always checked.

Make config_get_mode_setting() always return a valid c-string.

Use MODE_CHARGING as fallback value, and remove any alternative fallback
strategies used elsewhere in the code base.
Signed-off-by: spiiroin's avatarSimo Piiroinen <>
parent 92bcb718
......@@ -400,11 +400,20 @@ static char * config_get_kcmdline_string(const char *entry)
char * config_get_mode_setting(void)
char * mode = config_get_kcmdline_string(MODE_SETTING_KEY);
if (mode != NULL)
char *mode = 0;
return(config_get_conf_string(MODE_SETTING_ENTRY, MODE_SETTING_KEY));
/* Kernel command line can be used to override settings */
if( (mode = config_get_kcmdline_string(MODE_SETTING_KEY)) )
goto EXIT;
if( (mode = config_get_conf_string(MODE_SETTING_ENTRY, MODE_SETTING_KEY)) )
goto EXIT;
/* If no default mode is configured, treat it as charging only */
mode = g_strdup(MODE_CHARGING);
return mode;
* @param settingsfile: already opened settingsfile we want to read an entry from
......@@ -417,13 +417,6 @@ static DBusHandlerResult umdbus_msg_handler(DBusConnection *const connection, DB
char *config = config_get_mode_setting();
/* 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);
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