(menu_cbs_get_value.c) Put protective guards around strlcpy copies

into s2
This commit is contained in:
LibretroAdmin 2025-01-21 03:57:08 +01:00
parent e9afd53351
commit a49196ee30
1 changed files with 92 additions and 45 deletions

View File

@ -79,6 +79,7 @@ static void menu_action_setting_audio_mixer_stream_name(
{
unsigned offset = (type - MENU_SETTINGS_AUDIO_MIXER_STREAM_BEGIN);
*w = 19;
if (!string_is_empty(path))
strlcpy(s2, path, len2);
if (offset >= AUDIO_MIXER_MAX_SYSTEM_STREAMS)
return;
@ -96,6 +97,7 @@ static void menu_action_setting_audio_mixer_stream_volume(
size_t _len;
unsigned offset = (type - MENU_SETTINGS_AUDIO_MIXER_STREAM_ACTIONS_VOLUME_BEGIN);
*w = 19;
if (!string_is_empty(path))
strlcpy(s2, path, len2);
if (offset >= AUDIO_MIXER_MAX_SYSTEM_STREAMS)
return;
@ -114,6 +116,7 @@ static void menu_action_setting_disp_set_label_cheat_num_passes(
char *s2, size_t len2)
{
*w = 19;
if (!string_is_empty(path))
strlcpy(s2, path, len2);
snprintf(s, len, "%u", cheat_manager_get_buf_size());
}
@ -129,6 +132,7 @@ static void menu_action_setting_disp_set_label_cheevos_entry(
char *s2, size_t len2)
{
*w = 19;
if (!string_is_empty(path))
strlcpy(s2, path, len2);
rcheevos_menu_get_state(type - MENU_SETTINGS_CHEEVOS_START, s, len);
}
@ -145,6 +149,7 @@ static void menu_action_setting_disp_set_label_remap_file_info(
runloop_state_t *runloop_st = runloop_state_get_ptr();
const char *remap_path = runloop_st->name.remapfile;
*w = 19;
if (!string_is_empty(path))
strlcpy(s2, path, len2);
if (!string_is_empty(remap_path))
strlcpy(s, path_basename_nocompression(remap_path), len);
@ -162,6 +167,7 @@ static void menu_action_setting_disp_set_label_override_file_info(
{
const char *override_path = path_get(RARCH_PATH_CONFIG_OVERRIDE);
*w = 19;
if (!string_is_empty(path))
strlcpy(s2, path, len2);
if (!string_is_empty(override_path))
strlcpy(s, path_basename_nocompression(override_path), len);
@ -178,6 +184,7 @@ static void menu_action_setting_disp_set_label_configurations(
char *s2, size_t len2)
{
*w = 19;
if (!string_is_empty(path))
strlcpy(s2, path, len2);
if (!path_is_empty(RARCH_PATH_CONFIG))
fill_pathname_base(s, path_get(RARCH_PATH_CONFIG),
@ -199,6 +206,7 @@ static void menu_action_setting_disp_set_label_shader_filter_pass(
struct video_shader_pass *shader_pass = shader ? &shader->pass[type - MENU_SETTINGS_SHADER_PASS_FILTER_0] : NULL;
*s = '\0';
*w = 19;
if (!string_is_empty(path))
strlcpy(s2, path, len2);
if (shader_pass)
{
@ -232,6 +240,7 @@ static void menu_action_setting_disp_set_label_shader_watch_for_changes(
list->list[i].actiondata;
bool val = *cbs->setting->value.target.boolean;
*w = 19;
if (!string_is_empty(path))
strlcpy(s2, path, len2);
if (val)
strlcpy(s, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_TRUE), len);
@ -250,6 +259,7 @@ static void menu_action_setting_disp_set_label_shader_num_passes(
struct video_shader *shader = menu_shader_get();
unsigned pass_count = shader ? shader->passes : 0;
*w = 19;
if (!string_is_empty(path))
strlcpy(s2, path, len2);
snprintf(s, len, "%u", pass_count);
}
@ -265,6 +275,7 @@ static void menu_action_setting_disp_set_label_shader_pass(
struct video_shader *shader = menu_shader_get();
struct video_shader_pass *shader_pass = shader ? &shader->pass[type - MENU_SETTINGS_SHADER_PASS_0] : NULL;
*w = 19;
if (!string_is_empty(path))
strlcpy(s2, path, len2);
if (shader_pass && !string_is_empty(shader_pass->source.path))
fill_pathname_base(s, shader_pass->source.path, len);
@ -302,6 +313,7 @@ static void menu_action_setting_disp_set_label_shader_parameter_internal(
video_shader_ctx_t shader_info;
const struct video_shader_parameter *param = NULL;
*w = 19;
if (!string_is_empty(path))
strlcpy(s2, path, len2);
video_shader_driver_get_current_shader(&shader_info);
if (shader_info.data && (param = &shader_info.data->parameters[type - offset]))
@ -352,6 +364,7 @@ static void menu_action_setting_disp_set_label_shader_scale_pass(
struct video_shader_pass *shader_pass = shader ? &shader->pass[type - MENU_SETTINGS_SHADER_PASS_SCALE_0] : NULL;
*s = '\0';
*w = 19;
if (!string_is_empty(path))
strlcpy(s2, path, len2);
if (!shader_pass)
return;
@ -374,6 +387,7 @@ static void menu_action_setting_disp_set_label_netplay_mitm_server(
menu_file_list_cbs_t *cbs = (menu_file_list_cbs_t*)list->list[i].actiondata;
*w = 19;
*s = '\0';
if (!string_is_empty(path))
strlcpy(s2, path, len2);
if (!cbs || !cbs->setting)
return;
@ -518,8 +532,10 @@ static void menu_action_setting_disp_set_label_core_manager_steam_entry(
*s = '\0';
*w = 0;
if (MIST_IS_ERROR(steam_get_core_dlcs(&core_dlc_list, true))) return;
if (MIST_IS_ERROR(steam_get_core_dlcs(&core_dlc_list, true)))
return;
if (!string_is_empty(path))
strlcpy(s2, path, len2);
if (!(core_dlc = steam_get_core_dlc_by_name(core_dlc_list, path)))
@ -799,6 +815,8 @@ static void menu_action_setting_disp_set_label_input_desc(
return;
*w = 19;
if (!string_is_empty(path))
strlcpy(s2, path, len2);
if ((remap_idx = settings->uints.input_remap_ids[user_idx][btn_idx]) !=
@ -874,6 +892,8 @@ static void menu_action_setting_disp_set_label_input_desc_kbd(
}
*w = 19;
if (!string_is_empty(path))
strlcpy(s2, path, len2);
}
@ -910,6 +930,8 @@ static void menu_action_setting_disp_set_label_cheat(
cheat_manager_state.cheats[cheat_index].address);
}
*w = 19;
if (!string_is_empty(path))
strlcpy(s2, path, len2);
}
@ -930,6 +952,7 @@ static void menu_action_setting_disp_set_label_cheat_match(
/* TODO/FIXME - localize */
snprintf(s, len, "Prev: %u Curr: %u", prev_val, curr_val);
*w = 19;
if (!string_is_empty(path))
strlcpy(s2, path, len2);
}
#endif
@ -963,6 +986,7 @@ static void general_disp_set_label_perf_counters(
gfx_animation_t *p_anim = anim_get_ptr();
*s = '\0';
*w = 19;
if (!string_is_empty(path))
strlcpy(s2, path, len2);
menu_action_setting_disp_set_label_perf_counters_common(
@ -1042,7 +1066,7 @@ static void menu_action_setting_disp_set_label_entry_url(
if (!string_is_empty(representation_label))
strlcpy(s2, representation_label, len2);
else
else if (!string_is_empty(path))
strlcpy(s2, path, len2);
}
@ -1069,8 +1093,9 @@ static void menu_action_setting_disp_set_label_bluetooth_is_connected(
const char *path,
char *s2, size_t len2)
{
strlcpy(s2, path, len2);
*w = 19;
if (!string_is_empty(path))
strlcpy(s2, path, len2);
if (driver_bluetooth_device_is_connected(i))
strlcpy(s, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_BT_CONNECTED), len);
@ -1086,8 +1111,9 @@ static void menu_action_setting_disp_set_label_wifi_is_online(
const char *path,
char *s2, size_t len2)
{
strlcpy(s2, path, len2);
*w = 19;
if (!string_is_empty(path))
strlcpy(s2, path, len2);
if (driver_wifi_ssid_is_online(i))
strlcpy(s, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_ONLINE), len);
@ -1114,6 +1140,7 @@ static void menu_action_setting_disp_set_label_menu_disk_index(
*w = 19;
*s = '\0';
if (!string_is_empty(path))
strlcpy(s2, path, len2);
images = disk_control_get_num_images(&sys_info->disk_control);
@ -1138,6 +1165,7 @@ static void menu_action_setting_disp_set_label_menu_video_resolution(
*w = 19;
*s = '\0';
if (!string_is_empty(path))
strlcpy(s2, path, len2);
if (video_driver_get_video_output_size(&width, &height, desc, sizeof(desc)))
@ -1164,6 +1192,7 @@ static void menu_action_setting_disp_set_label_menu_video_resolution(
*s = '\0'; \
strlcpy(s, label, len); \
*w = label_size; \
if (!string_is_empty(path)) \
strlcpy(s2, path, len2)
static void menu_action_setting_disp_set_label_menu_file_plain(
@ -1243,6 +1272,7 @@ static void menu_action_setting_disp_set_label_generic(
{
*s = '\0';
*w = 0;
if (!string_is_empty(path))
strlcpy(s2, path, len2);
}
@ -1395,6 +1425,7 @@ static void menu_action_setting_disp_set_label_core_option_override_info(
else
strlcpy(s, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NOT_AVAILABLE), len);
if (!string_is_empty(path))
strlcpy(s2, path, len2);
}
@ -1411,6 +1442,7 @@ static void menu_action_setting_disp_set_label_playlist_associations(file_list_t
*s = '\0';
*w = 19;
if (!string_is_empty(path))
strlcpy(s2, path, len2);
if (!playlist)
@ -1443,6 +1475,7 @@ static void menu_action_setting_disp_set_label_playlist_label_display_mode(
*w = 19;
if (!string_is_empty(path))
strlcpy(s2, path, len2);
switch (label_display_mode)
@ -1507,6 +1540,7 @@ static void menu_action_setting_disp_set_label_playlist_right_thumbnail_mode(
*w = 19;
if (!string_is_empty(path))
strlcpy(s2, path, len2);
if (playlist)
@ -1530,6 +1564,7 @@ static void menu_action_setting_disp_set_label_playlist_left_thumbnail_mode(
*w = 19;
if (!string_is_empty(path))
strlcpy(s2, path, len2);
if (playlist)
@ -1558,6 +1593,7 @@ static void menu_action_setting_disp_set_label_playlist_sort_mode(
sort_mode = playlist_get_sort_mode(playlist);
*w = 19;
if (!string_is_empty(path))
strlcpy(s2, path, len2);
switch (sort_mode)
@ -1607,6 +1643,7 @@ static void menu_action_setting_disp_set_label_core_options(
if (string_is_empty(desc))
desc = msg_hash_to_str(MENU_ENUM_LABEL_VALUE_CORE_OPTIONS);
if (!string_is_empty(desc))
strlcpy(s2, desc, len2);
}
@ -1631,6 +1668,7 @@ static void menu_action_setting_disp_set_label_core_option(
strlcpy(s, coreopt_label, len);
}
if (!string_is_empty(path))
strlcpy(s2, path, len2);
}
@ -1652,6 +1690,7 @@ static void menu_action_setting_disp_set_label_achievement_information(
else
*s = '\0';
if (!string_is_empty(path))
strlcpy(s2, path, len2);
}
@ -1666,6 +1705,7 @@ static void menu_action_setting_disp_set_label_manual_content_scan_dir(
const char *content_dir = NULL;
*w = 19;
if (!string_is_empty(path))
strlcpy(s2, path, len2);
if (manual_content_scan_get_menu_content_dir(&content_dir))
@ -1686,6 +1726,7 @@ static void menu_action_setting_disp_set_label_manual_content_scan_system_name(
*w = 19;
if (!string_is_empty(path))
strlcpy(s2, path, len2);
if (manual_content_scan_get_menu_system_name(&system_name))
@ -1705,6 +1746,7 @@ static void menu_action_setting_disp_set_label_manual_content_scan_core_name(fil
*w = 19;
if (!string_is_empty(path))
strlcpy(s2, path, len2);
if (manual_content_scan_get_menu_core_name(&core_name))
@ -1724,6 +1766,7 @@ static void menu_action_setting_disp_set_label_no_items(
*s = '\0';
*w = 19;
if (!string_is_empty(path))
strlcpy(s2, path, len2);
}
@ -1745,6 +1788,7 @@ static void menu_action_setting_disp_set_label(file_list_t* list,
else
*s = '\0';
if (!string_is_empty(path))
strlcpy(s2, path, len2);
}
@ -1771,6 +1815,7 @@ static void menu_action_setting_disp_set_label_setting_bool(file_list_t* list,
else
*s = '\0';
if (!string_is_empty(path))
strlcpy(s2, path, len2);
}
@ -1789,6 +1834,7 @@ static void menu_action_setting_disp_set_label_setting_string(file_list_t* list,
if (setting->value.target.string)
strlcpy(s, setting->value.target.string, len);
if (!string_is_empty(path))
strlcpy(s2, path, len2);
}
@ -1808,6 +1854,7 @@ static void menu_action_setting_disp_set_label_setting_path(file_list_t* list,
if (!string_is_empty(basename))
strlcpy(s, basename, len);
if (!string_is_empty(path))
strlcpy(s2, path, len2);
}