Don't do NULL termination on string when we pass the string to

strlcpy and/or a file_path function that does strlcpy under the hood
This commit is contained in:
libretroadmin 2022-07-23 10:44:41 +02:00
parent f5ee9e74ba
commit 34a18f64e8
7 changed files with 28 additions and 136 deletions

View File

@ -2890,9 +2890,6 @@ void config_set_defaults(void *data)
#if TARGET_OS_IPHONE
{
char config_file_path[PATH_MAX_LENGTH];
config_file_path[0] = '\0';
fill_pathname_join(config_file_path,
settings->paths.directory_menu_config,
FILE_PATH_MAIN_CONFIG,
@ -3168,11 +3165,7 @@ static config_file_t *open_default_config_file(void)
{
bool dir_created = false;
char basedir[PATH_MAX_LENGTH];
basedir[0] = '\0';
/* Try to create a new config file. */
fill_pathname_basedir(basedir, application_data, sizeof(basedir));
fill_pathname_join(conf_path, application_data,
FILE_PATH_MAIN_CONFIG, sizeof(conf_path));
@ -3183,16 +3176,11 @@ static config_file_t *open_default_config_file(void)
{
char skeleton_conf[PATH_MAX_LENGTH];
bool saved = false;
skeleton_conf[0] = '\0';
/* Build a retroarch.cfg path from the
* global config directory (/etc). */
fill_pathname_join(skeleton_conf, GLOBAL_CONFIG_DIR,
FILE_PATH_MAIN_CONFIG, sizeof(skeleton_conf));
conf = config_file_new_from_path_to_string(skeleton_conf);
if (conf)
if ((conf = config_file_new_from_path_to_string(skeleton_conf)))
RARCH_WARN("[Config]: Using skeleton config \"%s\" as base for a new config file.\n", skeleton_conf);
else
conf = config_file_new_alloc();
@ -4247,9 +4235,6 @@ static void save_keybind_joykey(config_file_t *conf,
const struct retro_keybind *bind, bool save_empty)
{
char key[64];
key[0] = '\0';
fill_pathname_join_delim(key, prefix,
base, '_', sizeof(key));
strlcat(key, "_btn", sizeof(key));
@ -4271,11 +4256,6 @@ static void save_keybind_axis(config_file_t *conf,
const struct retro_keybind *bind, bool save_empty)
{
char key[64];
unsigned axis = 0;
char dir = '\0';
key[0] = '\0';
fill_pathname_join_delim(key, prefix, base, '_', sizeof(key));
strlcat(key, "_axis", sizeof(key));
@ -4286,22 +4266,16 @@ static void save_keybind_axis(config_file_t *conf,
}
else if (AXIS_NEG_GET(bind->joyaxis) != AXIS_DIR_NONE)
{
dir = '-';
axis = AXIS_NEG_GET(bind->joyaxis);
char config[16];
config[0] = '\0';
snprintf(config, sizeof(config), "-%u", AXIS_NEG_GET(bind->joyaxis));
config_set_string(conf, key, config);
}
else if (AXIS_POS_GET(bind->joyaxis) != AXIS_DIR_NONE)
{
dir = '+';
axis = AXIS_POS_GET(bind->joyaxis);
}
if (dir)
{
char config[16];
config[0] = '\0';
snprintf(config, sizeof(config), "%c%u", dir, axis);
snprintf(config, sizeof(config), "+%u", AXIS_POS_GET(bind->joyaxis));
config_set_string(conf, key, config);
}
}
@ -4312,9 +4286,6 @@ static void save_keybind_mbutton(config_file_t *conf,
const struct retro_keybind *bind, bool save_empty)
{
char key[64];
key[0] = '\0';
fill_pathname_join_delim(key, prefix,
base, '_', sizeof(key));
strlcat(key, "_mbtn", sizeof(key));
@ -4434,7 +4405,7 @@ static void input_config_save_keybinds_user(config_file_t *conf, unsigned user)
continue;
base = keybind->base;
key[0] = btn[0] = '\0';
btn[0] = '\0';
fill_pathname_join_delim(key, prefix, base, '_', sizeof(key));
@ -4472,9 +4443,6 @@ bool config_save_autoconf_profile(const
const char *joypad_driver = NULL;
char *sanitised_name = NULL;
buf[0] = '\0';
autoconf_file[0] = '\0';
if (string_is_empty(device_name))
goto end;
@ -4840,7 +4808,6 @@ bool config_save_overrides(enum override_type type, void *data)
bool has_content = !string_is_empty(rarch_path_basename);
config_directory[0] = '\0';
override_directory[0] = '\0';
core_path[0] = '\0';
game_path[0] = '\0';
content_path[0] = '\0';
@ -5142,8 +5109,6 @@ bool input_remapping_load_file(void *data, const char *path)
char btn_ident[128];
char key_ident[128];
btn_ident[0] = key_ident[0] = '\0';
fill_pathname_join_delim(btn_ident, s1,
key_string, '_', sizeof(btn_ident));
fill_pathname_join_delim(key_ident, s2,
@ -5171,9 +5136,6 @@ bool input_remapping_load_file(void *data, const char *path)
int stk_remap = -1;
int key_remap = -1;
stk_ident[0] = '\0';
key_ident[0] = '\0';
fill_pathname_join_delim(stk_ident, s3,
key_string, '_', sizeof(stk_ident));
@ -5300,9 +5262,6 @@ bool input_remapping_save_file(const char *path)
unsigned remap_id = settings->uints.input_remap_ids[i][j];
unsigned keymap_id = settings->uints.input_keymapper_ids[i][j];
btn_ident[0] = '\0';
key_ident[0] = '\0';
fill_pathname_join_delim(btn_ident, s1,
key_string, '_', sizeof(btn_ident));
fill_pathname_join_delim(key_ident, s2,
@ -5336,9 +5295,6 @@ bool input_remapping_save_file(const char *path)
unsigned remap_id = settings->uints.input_remap_ids[i][j];
unsigned keymap_id = settings->uints.input_keymapper_ids[i][j];
stk_ident[0] = '\0';
key_ident[0] = '\0';
fill_pathname_join_delim(stk_ident, s3,
key_string, '_', sizeof(stk_ident));
fill_pathname_join_delim(key_ident, s2,
@ -5429,9 +5385,7 @@ void config_load_file_salamander(void)
return;
/* Open config file */
config = config_file_new_from_path_to_string(config_path);
if (!config)
if (!(config = config_file_new_from_path_to_string(config_path)))
return;
/* Read 'libretro_path' value and update
@ -5582,8 +5536,6 @@ void input_config_set_autoconfig_binds(unsigned port, void *data)
{
char str[256];
const char *base = keybind->base;
str[0] = '\0';
fill_pathname_join_delim(str, "input", base, '_', sizeof(str));
input_config_parse_joy_button(str, config, "input", base, &binds[i]);
@ -5603,7 +5555,7 @@ void input_config_parse_mouse_button(
config_file_t *conf = (config_file_t*)conf_data;
struct retro_keybind *bind = (struct retro_keybind*)bind_data;
tmp[0] = key[0] = '\0';
tmp[0] = '\0';
fill_pathname_join_delim(key, s, "mbtn", '_', sizeof(key));
@ -5671,7 +5623,7 @@ void input_config_parse_joy_axis(
struct retro_keybind *bind = (struct retro_keybind*)bind_data;
struct config_entry_list *tmp_a = NULL;
tmp[0] = key[0] = key_label[0] = '\0';
tmp[0] = '\0';
fill_pathname_join_delim(key, s,
"axis", '_', sizeof(key));
@ -5762,7 +5714,7 @@ void input_config_parse_joy_button(
struct retro_keybind *bind = (struct retro_keybind*)bind_data;
struct config_entry_list *tmp_a = NULL;
tmp[0] = key[0] = key_label[0] = '\0';
tmp[0] = '\0';
fill_pathname_join_delim(key, s,
"btn", '_', sizeof(key));

View File

@ -2220,8 +2220,6 @@ static bool core_info_list_update_missing_firmware_internal(
if (!info)
return false;
path[0] = '\0';
for (i = 0; i < info->firmware_count; i++)
{
if (string_is_empty(info->firmware[i].path))

View File

@ -400,19 +400,15 @@ static bool core_updater_list_set_paths(
* source files have non-standard file names (which
* will not be recognised by regular core handling
* routines) */
bool resolve_symlinks = (list_type != CORE_UPDATER_LIST_TYPE_PFD);
char remote_core_path[PATH_MAX_LENGTH];
char local_core_path[PATH_MAX_LENGTH];
char local_info_path[PATH_MAX_LENGTH];
bool resolve_symlinks = (list_type != CORE_UPDATER_LIST_TYPE_PFD);
remote_core_path[0] = '\0';
local_core_path[0] = '\0';
local_info_path[0] = '\0';
if (!entry ||
string_is_empty(filename_str) ||
string_is_empty(path_dir_libretro) ||
string_is_empty(path_libretro_info))
if ( !entry
|| string_is_empty(filename_str)
|| string_is_empty(path_dir_libretro)
|| string_is_empty(path_libretro_info))
return false;
/* Only buildbot cores require the buildbot URL */
@ -459,7 +455,6 @@ static bool core_updater_list_set_paths(
entry->remote_core_path = strdup(remote_core_path);
/* local_core_path */
fill_pathname_join(
local_core_path,
path_dir_libretro,
@ -480,7 +475,6 @@ static bool core_updater_list_set_paths(
entry->local_core_path = strdup(local_core_path);
/* local_info_path */
fill_pathname_join(
local_info_path,
path_libretro_info,
@ -529,9 +523,9 @@ static bool core_updater_list_set_core_info(
{
core_updater_info_t *core_info = NULL;
if (!entry ||
string_is_empty(local_info_path) ||
string_is_empty(filename_str))
if ( !entry
|| string_is_empty(local_info_path)
|| string_is_empty(filename_str))
return false;
/* Clear any existing core info */
@ -563,9 +557,7 @@ static bool core_updater_list_set_core_info(
* Would be better to cache this globally
* (at present, we only cache info for
* *installed* cores...) */
core_info = core_info_get_core_updater_info(local_info_path);
if (core_info)
if ((core_info = core_info_get_core_updater_info(local_info_path)))
{
/* display_name + is_experimental */
if (!string_is_empty(core_info->display_name))
@ -687,9 +679,9 @@ static void core_updater_list_add_entry(
crc_str = network_core_entry_list->elems[1].data;
filename_str = network_core_entry_list->elems[2].data;
if (string_is_empty(date_str) ||
string_is_empty(crc_str) ||
string_is_empty(filename_str))
if ( string_is_empty(date_str)
|| string_is_empty(crc_str)
|| string_is_empty(filename_str))
goto error;
/* Check whether core file is already included

View File

@ -222,8 +222,6 @@ bool disk_index_file_init(
char disk_index_file_dir[PATH_MAX_LENGTH];
char disk_index_file_path[PATH_MAX_LENGTH];
disk_index_file_path[0] = '\0';
/* Sanity check */
if (!disk_index_file)
return false;

View File

@ -184,10 +184,7 @@ void fill_pathname_application_special(char *s,
{
char s1[PATH_MAX_LENGTH];
char s2[PATH_MAX_LENGTH];
s1[0] = '\0';
s2[0] = '\0';
fill_pathname_application_special(s1, sizeof(s1),
APPLICATION_SPECIAL_DIRECTORY_ASSETS_XMB);
fill_pathname_join(s2, s1, "png", sizeof(s2));
@ -340,9 +337,6 @@ void fill_pathname_application_special(char *s,
char rgui_dir[PATH_MAX_LENGTH];
settings_t *settings = config_get_ptr();
const char *dir_assets = settings->paths.directory_assets;
rgui_dir[0] = '\0';
fill_pathname_join(rgui_dir, dir_assets, "rgui",
sizeof(rgui_dir));
fill_pathname_join(s,
@ -357,9 +351,6 @@ void fill_pathname_application_special(char *s,
char s1[PATH_MAX_LENGTH];
settings_t *settings = config_get_ptr();
const char *dir_assets = settings->paths.directory_assets;
s1[0] = '\0';
fill_pathname_join(s1, dir_assets, "xmb", sizeof(s1));
fill_pathname_join(s,
s1, xmb_theme_ident(), len);
@ -462,13 +453,8 @@ void fill_pathname_application_special(char *s,
char s2[PATH_MAX_LENGTH];
settings_t *settings = config_get_ptr();
const char *dir_thumbnails = settings->paths.directory_thumbnails;
s1[0] = '\0';
s2[0] = '\0';
fill_pathname_join(s1, dir_thumbnails, "discord", sizeof(s1));
fill_pathname_join(s2,
s1, "avatars", sizeof(s2));
fill_pathname_join(s2, s1, "avatars", sizeof(s2));
fill_pathname_slash(s2, sizeof(s2));
strlcpy(s, s2, len);
}
@ -480,13 +466,8 @@ void fill_pathname_application_special(char *s,
char s2[PATH_MAX_LENGTH];
settings_t *settings = config_get_ptr();
const char *dir_thumbnails = settings->paths.directory_thumbnails;
s1[0] = '\0';
s2[0] = '\0';
fill_pathname_join(s1, dir_thumbnails, "cheevos", len);
fill_pathname_join(s2,
s1, "badges", sizeof(s2));
fill_pathname_join(s2, s1, "badges", sizeof(s2));
fill_pathname_slash(s2, sizeof(s2));
strlcpy(s, s2, len);
}

View File

@ -2097,7 +2097,6 @@ static int menu_displaylist_parse_playlist(menu_displaylist_info_t *info,
bool pl_show_sublabels = settings->bools.playlist_show_sublabels;
void (*sanitization)(char*);
label_spacer[0] = '\0';
info->count = 0;
if (list_size == 0)
@ -2144,8 +2143,6 @@ static int menu_displaylist_parse_playlist(menu_displaylist_info_t *info,
else if (!string_is_empty(info->path))
{
char lpl_basename[256];
lpl_basename[0] = '\0';
fill_pathname_base(lpl_basename, info->path, sizeof(lpl_basename));
path_remove_extension(lpl_basename);
menu_driver_set_thumbnail_system(lpl_basename, sizeof(lpl_basename));
@ -2185,8 +2182,6 @@ static int menu_displaylist_parse_playlist(menu_displaylist_info_t *info,
const char *entry_path = NULL;
bool entry_valid = true;
menu_entry_label[0] = '\0';
/* Read playlist entry */
playlist_get_index(playlist, i, &entry);
@ -2398,7 +2393,7 @@ static int menu_displaylist_parse_database_entry(menu_handle_t *menu,
playlist_config.fuzzy_archive_match = settings->bools.playlist_fuzzy_archive_match;
playlist_config_set_base_content_directory(&playlist_config, settings->bools.playlist_portable_paths ? settings->paths.directory_menu_content : NULL);
path_playlist[0] = path_base[0] = query[0] = '\0';
query[0] = '\0';
database_info_build_query_enum(query, sizeof(query),
DATABASE_QUERY_ENTRY, info->path_b);
@ -3279,9 +3274,6 @@ static int menu_displaylist_parse_horizontal_list(
char path_playlist[PATH_MAX_LENGTH];
const char *dir_playlist = settings->paths.directory_playlist;
lpl_basename[0] = '\0';
path_playlist[0] = '\0';
fill_pathname_join(path_playlist, dir_playlist, item->path,
sizeof(path_playlist));
@ -4170,9 +4162,6 @@ static unsigned menu_displaylist_parse_cores(
{
char out_dir[PATH_MAX_LENGTH];
out_dir[0] = '\0';
fill_pathname_parent_dir(out_dir, path, sizeof(out_dir));
if (string_is_empty(out_dir))
@ -4299,7 +4288,6 @@ static unsigned menu_displaylist_parse_cores(
{
char core_path[PATH_MAX_LENGTH];
char display_name[PATH_MAX_LENGTH];
core_path[0] =
display_name[0] = '\0';
fill_pathname_join(core_path, dir, path, sizeof(core_path));
@ -4566,8 +4554,6 @@ static unsigned menu_displaylist_parse_pl_thumbnail_download_list(
char path_base[PATH_MAX_LENGTH];
const char *path;
path_base[0] = '\0';
if (str_list->elems[i].attr.i == FILE_TYPE_DIRECTORY)
continue;
@ -11503,14 +11489,11 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type,
char combined_path[PATH_MAX_LENGTH];
const char *ext = NULL;
combined_path[0] = '\0';
fill_pathname_join(combined_path, menu->scratch2_buf,
menu->scratch_buf, sizeof(combined_path));
ext = path_get_extension(combined_path);
if (audio_driver_mixer_extension_supported(ext))
{
if (menu_entries_append_enum(info->list,
@ -11931,16 +11914,12 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type,
const char *
network_buildbot_assets_url = settings->paths.network_buildbot_assets_url;
new_label[0] = '\0';
fill_pathname_join(new_label,
network_buildbot_assets_url,
"cores", sizeof(new_label));
count = print_buf_lines(info->list, menu->core_buf, new_label,
(int)menu->core_len, FILE_TYPE_DOWNLOAD_URL, true, false);
if (count == 0)
if ((count = print_buf_lines(info->list, menu->core_buf, new_label,
(int)menu->core_len, FILE_TYPE_DOWNLOAD_URL, true, false)) == 0)
menu_entries_append_enum(info->list,
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NO_ENTRIES_TO_DISPLAY),
msg_hash_to_str(MENU_ENUM_LABEL_NO_ENTRIES_TO_DISPLAY),
@ -12141,9 +12120,6 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type,
char path_playlist[PATH_MAX_LENGTH];
playlist_t *playlist = NULL;
const char *dir_playlist = settings->paths.directory_playlist;
path_playlist[0] = '\0';
fill_pathname_join(
path_playlist,
dir_playlist,

View File

@ -1080,11 +1080,8 @@ static bool validate_per_core_options(char *s,
if (mkdir && !path_is_valid(s))
{
char new_path[PATH_MAX_LENGTH];
new_path[0] = '\0';
fill_pathname_join(new_path,
config_directory, core_name, sizeof(new_path));
if (!path_is_directory(new_path))
path_mkdir(new_path);
}
@ -1235,7 +1232,6 @@ static void runloop_init_core_options_path(
bool per_core_options = !settings->bools.global_core_options;
const char *path_core_options = settings->paths.path_core_options;
global_options_path[0] = '\0';
per_core_options_path[0] = '\0';
if (per_core_options)
@ -3937,7 +3933,6 @@ static char *copy_core_to_temp_file(
if (!(tmpdir = get_tmpdir_alloc(dir_libretro)))
return NULL;
tmp_path[0] = '\0';
fill_pathname_join(tmp_path,
tmpdir, "retroarch_temp",
sizeof(tmp_path));