Merge pull request #980 from lioncash/deref

settings_data: Handle potential null dereferences
This commit is contained in:
Twinaphex 2014-09-12 04:17:51 +02:00
commit d9fbfb8fdc

View File

@ -41,6 +41,18 @@
static void get_input_config_prefix(char *buf, size_t sizeof_buf,
const rarch_setting_t *setting)
{
if (!buf)
{
RARCH_ERR("Null buffer passed to %s", __FUNCTION__);
return;
}
if (!setting)
{
RARCH_ERR("Null setting passed to %s", __FUNCTION__);
return;
}
snprintf(buf, sizeof_buf, "input%cplayer%u",
setting->index ? '_' : '\0', setting->index);
}
@ -49,6 +61,19 @@ static void get_input_config_key(char *buf, size_t sizeof_buf,
const rarch_setting_t* setting, const char* type)
{
char prefix[32];
if (!buf)
{
RARCH_ERR("Null buffer passed to %s", __FUNCTION__);
return;
}
if (!setting)
{
RARCH_ERR("Null setting passed to %s", __FUNCTION__);
return;
}
get_input_config_prefix(prefix, sizeof(prefix), setting);
snprintf(buf, sizeof_buf, "%s_%s%c%s", prefix, setting->name,
type ? '_' : '\0', type);
@ -62,6 +87,18 @@ static void get_key_name(char *buf, size_t sizeof_buf,
{
uint32_t hidkey, i;
if (!buf)
{
RARCH_ERR("Null buffer passed to %s", __FUNCTION__);
return;
}
if (!setting)
{
RARCH_ERR("Null setting passed to %s", __FUNCTION__);
return;
}
if (BINDFOR(*setting).key == RETROK_UNKNOWN)
return;
@ -81,6 +118,18 @@ static void get_key_name(char *buf, size_t sizeof_buf,
static void get_button_name(char *buf, size_t sizeof_buf,
const rarch_setting_t* setting)
{
if (!buf)
{
RARCH_ERR("Null buffer passed to %s", __FUNCTION__);
return;
}
if (!setting)
{
RARCH_ERR("Null setting passed to %s", __FUNCTION__);
return;
}
if (BINDFOR(*setting).joykey == NO_BTN)
return;
@ -91,7 +140,21 @@ static void get_button_name(char *buf, size_t sizeof_buf,
static void get_axis_name(char *buf, size_t sizeof_buf,
const rarch_setting_t* setting)
{
uint32_t joyaxis = BINDFOR(*setting).joyaxis;
uint32_t joyaxis;
if (!buf)
{
RARCH_ERR("Null buffer passed to %s", __FUNCTION__);
return;
}
if (!setting)
{
RARCH_ERR("Null setting passed to %s", __FUNCTION__);
return;
}
joyaxis = BINDFOR(*setting).joyaxis;
if (AXIS_NEG_GET(joyaxis) != AXIS_DIR_NONE)
snprintf(buf, sizeof_buf, "-%u", AXIS_NEG_GET(joyaxis));
@ -101,6 +164,12 @@ static void get_axis_name(char *buf, size_t sizeof_buf,
void setting_data_reset_setting(const rarch_setting_t* setting)
{
if (!setting)
{
RARCH_ERR("Null setting passed to %s", __FUNCTION__);
return;
}
switch (setting->type)
{
case ST_BOOL:
@ -159,7 +228,7 @@ void setting_data_reset(const rarch_setting_t* settings)
static bool setting_data_load_config(
const rarch_setting_t* settings, config_file_t* config)
{
if (!config)
if (!settings || !config)
return false;
for (; settings->type != ST_NONE; settings++)
@ -266,7 +335,7 @@ bool setting_data_load_config_path(const rarch_setting_t* settings,
bool setting_data_save_config(const rarch_setting_t* settings,
config_file_t* config)
{
if (!config)
if (!settings || !config)
return false;
for (; settings->type != ST_NONE; settings++)
@ -366,7 +435,7 @@ rarch_setting_t* setting_data_find_setting(rarch_setting_t* setting,
{
bool found = false;
if (!name)
if (!setting || !name)
return NULL;
for (; setting->type != ST_NONE; setting++)
@ -460,8 +529,14 @@ void setting_data_set_with_string_representation(const rarch_setting_t* setting,
static void menu_common_setting_set_label_st_bool(rarch_setting_t *setting,
char *type_str, size_t type_str_size)
{
if (!setting)
{
RARCH_ERR("Null setting passed to %s", __FUNCTION__);
return;
}
if (!strcmp(setting->name, "savestate") ||
!strcmp(setting->name, "loadstate"))
!strcmp(setting->name, "loadstate"))
{
if (g_settings.state_slot < 0)
strlcpy(type_str, "-1 (auto)", type_str_size);
@ -469,14 +544,22 @@ static void menu_common_setting_set_label_st_bool(rarch_setting_t *setting,
snprintf(type_str, type_str_size, "%d", g_settings.state_slot);
}
else
{
strlcpy(type_str, *setting->value.boolean ? setting->boolean.on_label :
setting->boolean.off_label, type_str_size);
}
}
static void menu_common_setting_set_label_st_uint(rarch_setting_t *setting,
char *type_str, size_t type_str_size)
{
if (setting && !strcmp(setting->name, "video_monitor_index"))
if (!setting)
{
RARCH_ERR("Null setting passed to %s", __FUNCTION__);
return;
}
if (!strcmp(setting->name, "video_monitor_index"))
{
if (*setting->value.unsigned_integer)
snprintf(type_str, type_str_size, "%u",
@ -484,14 +567,18 @@ static void menu_common_setting_set_label_st_uint(rarch_setting_t *setting,
else
strlcpy(type_str, "0 (Auto)", type_str_size);
}
else if (setting && !strcmp(setting->name, "video_rotation"))
else if (!strcmp(setting->name, "video_rotation"))
{
strlcpy(type_str, rotation_lut[*setting->value.unsigned_integer],
type_str_size);
else if (setting && !strcmp(setting->name, "aspect_ratio_index"))
}
else if (!strcmp(setting->name, "aspect_ratio_index"))
{
strlcpy(type_str,
aspectratio_lut[*setting->value.unsigned_integer].name,
type_str_size);
else if (setting && !strcmp(setting->name, "autosave_interval"))
}
else if (!strcmp(setting->name, "autosave_interval"))
{
if (*setting->value.unsigned_integer)
snprintf(type_str, type_str_size, "%u seconds",
@ -499,7 +586,7 @@ static void menu_common_setting_set_label_st_uint(rarch_setting_t *setting,
else
strlcpy(type_str, "OFF", type_str_size);
}
else if (setting && !strcmp(setting->name, "user_language"))
else if (!strcmp(setting->name, "user_language"))
{
static const char *modes[] = {
"English",
@ -518,7 +605,7 @@ static void menu_common_setting_set_label_st_uint(rarch_setting_t *setting,
strlcpy(type_str, modes[g_settings.user_language], type_str_size);
}
else if (setting && !strcmp(setting->name, "libretro_log_level"))
else if (!strcmp(setting->name, "libretro_log_level"))
{
static const char *modes[] = {
"0 (Debug)",
@ -531,14 +618,22 @@ static void menu_common_setting_set_label_st_uint(rarch_setting_t *setting,
type_str_size);
}
else
{
snprintf(type_str, type_str_size, "%u",
*setting->value.unsigned_integer);
}
}
static void menu_common_setting_set_label_st_float(rarch_setting_t *setting,
char *type_str, size_t type_str_size)
{
if (setting && !strcmp(setting->name, "video_refresh_rate_auto"))
if (!setting)
{
RARCH_ERR("Null setting passed to %s", __FUNCTION__);
return;
}
if (!strcmp(setting->name, "video_refresh_rate_auto"))
{
double refresh_rate = 0.0;
double deviation = 0.0;
@ -551,8 +646,10 @@ static void menu_common_setting_set_label_st_float(rarch_setting_t *setting,
strlcpy(type_str, "N/A", type_str_size);
}
else
{
snprintf(type_str, type_str_size, setting->rounding_fraction,
*setting->value.fraction);
}
}
void setting_data_get_string_representation(rarch_setting_t* setting,
@ -1951,7 +2048,6 @@ static void general_write_handler(const void *data)
if (!setting)
return;
if (!strcmp(setting->name, "quit_retroarch"))
{
if (*setting->value.boolean)