From 88c2ae9ddfb421b2d4eb1493d60dc4aeca502c0e Mon Sep 17 00:00:00 2001 From: libretroadmin Date: Tue, 26 Jul 2022 13:23:28 +0200 Subject: [PATCH] No null termination for strings passed to strlcpy/srlcat --- gfx/common/vulkan_common.c | 6 +- gfx/drivers_shader/glslang_util_cxx.cpp | 6 +- gfx/drivers_shader/shader_glsl.c | 20 ++---- menu/cbs/menu_cbs_deferred_push.c | 1 - menu/cbs/menu_cbs_ok.c | 90 +++++++++++-------------- menu/cbs/menu_cbs_scan.c | 4 -- menu/cbs/menu_cbs_start.c | 4 -- menu/cbs/menu_cbs_sublabel.c | 12 +--- menu/menu_contentless_cores.c | 4 -- 9 files changed, 49 insertions(+), 98 deletions(-) diff --git a/gfx/common/vulkan_common.c b/gfx/common/vulkan_common.c index 05e475e679..2486a80f5b 100644 --- a/gfx/common/vulkan_common.c +++ b/gfx/common/vulkan_common.c @@ -1649,8 +1649,8 @@ static bool vulkan_context_init_device(gfx_ctx_vulkan_data_t *vk) char driver_version[64]; char api_version[64]; char version_str[128]; - int pos = 0; - device_str[0] = driver_version[0] = api_version[0] = version_str[0] = '\0'; + int pos = 0; + driver_version[0] = api_version[0] = '\0'; strlcpy(device_str, vk->context.gpu_properties.deviceName, sizeof(device_str)); strlcat(device_str, " ", sizeof(device_str)); @@ -1675,7 +1675,7 @@ static bool vulkan_context_init_device(gfx_ctx_vulkan_data_t *vk) strlcat(api_version, ".", sizeof(api_version)); pos += snprintf(api_version + pos, sizeof(api_version) - pos, "%u", VK_VERSION_PATCH(vk->context.gpu_properties.apiVersion)); - strlcat(version_str, api_version, sizeof(device_str)); + strlcpy(version_str, api_version, sizeof(device_str)); video_driver_set_gpu_device_string(device_str); video_driver_set_gpu_api_version_string(version_str); diff --git a/gfx/drivers_shader/glslang_util_cxx.cpp b/gfx/drivers_shader/glslang_util_cxx.cpp index a777c4dbd9..3877547667 100644 --- a/gfx/drivers_shader/glslang_util_cxx.cpp +++ b/gfx/drivers_shader/glslang_util_cxx.cpp @@ -65,12 +65,8 @@ static std::string build_stage_source( if (!string_is_empty(stage)) { char expected[128]; - - expected[0] = '\0'; - - strcpy_literal(expected, "#pragma stage "); + strlcpy(expected, "#pragma stage ", sizeof(expected)); strlcat(expected, stage, sizeof(expected)); - active = string_is_equal(expected, line); } } diff --git a/gfx/drivers_shader/shader_glsl.c b/gfx/drivers_shader/shader_glsl.c index 87fc9118aa..1781a4b28d 100644 --- a/gfx/drivers_shader/shader_glsl.c +++ b/gfx/drivers_shader/shader_glsl.c @@ -187,13 +187,9 @@ static GLint gl_glsl_get_uniform(glsl_shader_data_t *glsl, unsigned i; GLint loc; char buf[80]; - - buf[0] = '\0'; - strlcpy(buf, glsl->shader->prefix, sizeof(buf)); strlcat(buf, base, sizeof(buf)); - loc = glGetUniformLocation(prog, buf); - if (loc >= 0) + if ((loc = glGetUniformLocation(prog, buf)) >= 0) return loc; for (i = 0; i < ARRAY_SIZE(glsl_prefixes); i++) @@ -201,8 +197,7 @@ static GLint gl_glsl_get_uniform(glsl_shader_data_t *glsl, buf[0] = '\0'; strlcpy(buf, glsl_prefixes[i], sizeof(buf)); strlcat(buf, base, sizeof(buf)); - loc = glGetUniformLocation(prog, buf); - if (loc >= 0) + if ((loc = glGetUniformLocation(prog, buf)) >= 0) return loc; } @@ -215,21 +210,16 @@ static GLint gl_glsl_get_attrib(glsl_shader_data_t *glsl, unsigned i; GLint loc; char buf[80]; - - buf[0] = '\0'; - strlcpy(buf, glsl->shader->prefix, sizeof(buf)); strlcat(buf, base, sizeof(buf)); - loc = glGetUniformLocation(prog, buf); - if (loc >= 0) + if ((loc = glGetUniformLocation(prog, buf)) >= 0) return loc; for (i = 0; i < ARRAY_SIZE(glsl_prefixes); i++) { strlcpy(buf, glsl_prefixes[i], sizeof(buf)); strlcat(buf, base, sizeof(buf)); - loc = glGetAttribLocation(prog, buf); - if (loc >= 0) + if ((loc = glGetAttribLocation(prog, buf)) >= 0) return loc; } @@ -701,8 +691,6 @@ static void gl_glsl_find_uniforms_frame(glsl_shader_data_t *glsl, char input_size[64]; char tex_coord[64]; - texture[0] = texture_size[0] = input_size[0] = tex_coord[0] = '\0'; - strlcpy(texture, base, sizeof(texture)); strlcat(texture, "Texture", sizeof(texture)); strlcpy(texture_size, base, sizeof(texture_size)); diff --git a/menu/cbs/menu_cbs_deferred_push.c b/menu/cbs/menu_cbs_deferred_push.c index c3f05e1381..9e17a69ec1 100644 --- a/menu/cbs/menu_cbs_deferred_push.c +++ b/menu/cbs/menu_cbs_deferred_push.c @@ -515,7 +515,6 @@ static int general_push(menu_displaylist_info_t *info, struct retro_system_info *system = &runloop_state_get_ptr()->system.info; - newstring[0] = '\0'; attr.i = 0; string_list_initialize(&str_list2); diff --git a/menu/cbs/menu_cbs_ok.c b/menu/cbs/menu_cbs_ok.c index cf78593afe..dd7775794d 100644 --- a/menu/cbs/menu_cbs_ok.c +++ b/menu/cbs/menu_cbs_ok.c @@ -1157,7 +1157,6 @@ int generic_action_ok_displaylist_push(const char *path, /* Focus on current content entry */ { char path_content[PATH_MAX_LENGTH]; - path_content[0] = '\0'; strlcpy(path_content, path_get(RARCH_PATH_CONTENT), sizeof(path_content)); /* Remove archive browsed file from the path */ { @@ -1212,7 +1211,6 @@ int generic_action_ok_displaylist_push(const char *path, case ACTION_OK_DL_RGUI_MENU_THEME_PRESET: { char rgui_assets_dir[PATH_MAX_LENGTH]; - rgui_assets_dir[0] = '\0'; filebrowser_clear_type(); info.type = type; @@ -1361,7 +1359,6 @@ int generic_action_ok_displaylist_push(const char *path, case ACTION_OK_DL_DATABASE_MANAGER_LIST: { char lpl_basename[PATH_MAX_LENGTH]; - lpl_basename[0] = '\0'; filebrowser_clear_type(); fill_pathname_join(tmp, settings->paths.path_content_database, @@ -1967,8 +1964,6 @@ static int generic_action_ok(const char *path, menu_entries_get_last_stack(&menu_path, &menu_label, NULL, &enum_idx, NULL); - action_path[0] = '\0'; - if (!string_is_empty(path)) fill_pathname_join(action_path, menu_path, path, sizeof(action_path)); @@ -2294,8 +2289,6 @@ static int action_ok_file_load(const char *path, rarch_setting_t *setting = NULL; file_list_t *menu_stack = menu_entries_get_menu_stack_ptr(0); - menu_path_new[0] = full_path_new[0] = '\0'; - if (filebrowser_get_type() == FILEBROWSER_SELECT_FILE_SUBSYSTEM) { /* TODO/FIXME - this path is triggered when we try to load a @@ -2456,9 +2449,7 @@ static int action_ok_playlist_entry_collection(const char *path, goto error; /* Get playlist */ - tmp_playlist = playlist_get_cached(); - - if (!tmp_playlist) + if (!(tmp_playlist = playlist_get_cached())) { /* If playlist is not cached, have to load * it here @@ -2908,16 +2899,15 @@ static int action_ok_audio_add_to_mixer_and_collection(const char *path, struct playlist_entry entry = {0}; menu_handle_t *menu = menu_state_get_ptr()->driver_data; - combined_path[0] = '\0'; - if (!menu) return menu_cbs_exit(); fill_pathname_join(combined_path, menu->scratch2_buf, menu->scratch_buf, sizeof(combined_path)); - /* the push function reads our entry as const, so these casts are safe */ - entry.path = combined_path; + /* The push function reads our entry as const, + so these casts are safe */ + entry.path = combined_path; entry.core_path = (char*)"builtin"; entry.core_name = (char*)"musicplayer"; @@ -2939,8 +2929,6 @@ static int action_ok_audio_add_to_mixer_and_collection_and_play(const char *path struct playlist_entry entry = {0}; menu_handle_t *menu = menu_state_get_ptr()->driver_data; - combined_path[0] = '\0'; - if (!menu) return menu_cbs_exit(); @@ -3674,8 +3662,7 @@ static int action_ok_remap_file_flush(const char *path, if (!string_is_empty(path_remapfile)) { /* Update existing remap file */ - success = input_remapping_save_file(path_remapfile); - + success = input_remapping_save_file(path_remapfile); /* Get remap file name for display purposes */ remapfile = path_basename_nocompression(path_remapfile); } @@ -3684,16 +3671,26 @@ static int action_ok_remap_file_flush(const char *path, remapfile = msg_hash_to_str(MENU_ENUM_LABEL_VALUE_UNKNOWN); /* Log result */ - RARCH_LOG(success ? - "[Remaps]: Saved input remapping options to \"%s\".\n" : - "[Remaps]: Failed to save input remapping options to \"%s\".\n", + if (success) + { + RARCH_LOG( + "[Remaps]: Saved input remapping options to \"%s\".\n", path_remapfile ? path_remapfile : "UNKNOWN"); - snprintf(msg, sizeof(msg), "%s \"%s\"", - success ? - msg_hash_to_str(MSG_REMAP_FILE_FLUSHED) : - msg_hash_to_str(MSG_REMAP_FILE_FLUSH_FAILED), - remapfile); + snprintf(msg, sizeof(msg), "%s \"%s\"", + msg_hash_to_str(MSG_REMAP_FILE_FLUSHED), + remapfile); + } + else + { + RARCH_LOG( + "[Remaps]: Failed to save input remapping options to \"%s\".\n", + path_remapfile ? path_remapfile : "UNKNOWN"); + + snprintf(msg, sizeof(msg), "%s \"%s\"", + msg_hash_to_str(MSG_REMAP_FILE_FLUSH_FAILED), + remapfile); + } runloop_msg_queue_push( msg, 1, 100, true, @@ -3777,9 +3774,6 @@ static int action_ok_core_deferred_set(const char *new_core_path, char resolved_core_path[PATH_MAX_LENGTH]; char msg[PATH_MAX_LENGTH]; - resolved_core_path[0] = '\0'; - msg[0] = '\0'; - if (!menu || string_is_empty(new_core_path)) return menu_cbs_exit(); @@ -3949,9 +3943,6 @@ static int action_ok_audio_run(const char *path, { char combined_path[PATH_MAX_LENGTH]; menu_handle_t *menu = menu_state_get_ptr()->driver_data; - - combined_path[0] = '\0'; - if (!menu) return menu_cbs_exit(); @@ -4141,7 +4132,6 @@ static int action_ok_cheat_add_bottom(const char *path, menu_driver_ctl(RARCH_MENU_CTL_SET_PREVENT_POPULATE, NULL); cheat_manager_realloc(new_size, CHEAT_HANDLER_TYPE_EMU); - msg[0] = '\0'; strlcpy(msg, msg_hash_to_str(MSG_CHEAT_ADD_BOTTOM_SUCCESS), sizeof(msg)); msg[sizeof(msg) - 1] = 0; @@ -4158,7 +4148,6 @@ static int action_ok_cheat_delete_all(const char *path, char msg[256]; bool refresh = false; - msg[0] = '\0'; cheat_manager_state.delete_state = 0; cheat_manager_realloc(0, CHEAT_HANDLER_TYPE_EMU); menu_entries_ctl(MENU_ENTRIES_CTL_SET_REFRESH, &refresh); @@ -4588,20 +4577,28 @@ static int action_ok_core_updater_list(const char *path, static void cb_net_generic_subdir(retro_task_t *task, void *task_data, void *user_data, const char *err) { +#if 0 char subdir_path[PATH_MAX_LENGTH]; +#endif http_transfer_data_t *data = (http_transfer_data_t*)task_data; file_transfer_t *state = (file_transfer_t*)user_data; +#if 0 subdir_path[0] = '\0'; +#endif if (!data || err) goto finish; +#if 0 if (!string_is_empty(data->data)) memcpy(subdir_path, data->data, data->len * sizeof(char)); subdir_path[data->len] = '\0'; +#endif finish: + /* TODO/FIXME - unimplemented/unfinished code */ +#if 0 if (!err && !string_ends_with_size(subdir_path, FILE_PATH_INDEX_DIRS_URL, strlen(subdir_path), @@ -4609,15 +4606,12 @@ finish: )) { char parent_dir[PATH_MAX_LENGTH]; - - parent_dir[0] = '\0'; - fill_pathname_parent_dir(parent_dir, state->path, sizeof(parent_dir)); - /*generic_action_ok_displaylist_push(parent_dir, NULL, subdir_path, 0, 0, 0, ACTION_OK_DL_CORE_CONTENT_DIRS_SUBDIR_LIST);*/ } +#endif if (user_data) free(user_data); @@ -4668,7 +4662,6 @@ finish: char parent_dir_encoded[PATH_MAX_LENGTH]; file_transfer_t *transf = NULL; - parent_dir[0] = '\0'; parent_dir_encoded[0] = '\0'; fill_pathname_parent_dir(parent_dir, @@ -5003,7 +4996,7 @@ static int action_ok_download_generic(const char *path, settings->paths.network_buildbot_assets_url; const char *network_buildbot_url = settings->paths.network_buildbot_url; - s[0] = s2[0] = s3[0] = '\0'; + s3[0] = '\0'; fill_pathname_join(s, network_buildbot_assets_url, @@ -5016,7 +5009,7 @@ static int action_ok_download_generic(const char *path, fill_pathname_join(s, label, path, sizeof(s)); path = s; - cb = cb_generic_dir_download; + cb = cb_generic_dir_download; break; case MENU_ENUM_LABEL_CB_CORE_CONTENT_DOWNLOAD: { @@ -5186,8 +5179,6 @@ static int action_ok_sideload_core(const char *path, settings_t *settings = config_get_ptr(); const char *dir_libretro = settings->paths.directory_libretro; - backup_path[0] = '\0'; - if (string_is_empty(core_file) || !menu) return menu_cbs_exit(); @@ -5422,14 +5413,12 @@ static int action_ok_add_to_favorites(const char *path, char core_path[PATH_MAX_LENGTH]; char core_name[PATH_MAX_LENGTH]; - content_label[0] = '\0'; core_path[0] = '\0'; core_name[0] = '\0'; /* Create string list container for playlist parameters */ attr.i = 0; - str_list = string_list_new(); - if (!str_list) + if (!(str_list = string_list_new())) return 0; /* Determine playlist parameters */ @@ -5438,6 +5427,8 @@ static int action_ok_add_to_favorites(const char *path, if (!string_is_empty(runloop_st->name.label)) strlcpy(content_label, runloop_st->name.label, sizeof(content_label)); + else + content_label[0] = '\0'; /* Label is empty - use file name instead */ if (string_is_empty(content_label)) @@ -5453,8 +5444,8 @@ static int action_ok_add_to_favorites(const char *path, core_info_t *core_info = NULL; /* >> core_path */ - strlcpy(core_path, path_get(RARCH_PATH_CORE), sizeof(core_path)); - + strlcpy(core_path, path_get(RARCH_PATH_CORE), + sizeof(core_path)); /* >> core_name * (always use display name, if available) */ if (core_info_find(core_path, &core_info)) @@ -5557,8 +5548,7 @@ static int action_ok_add_to_favorites_playlist(const char *path, /* Create string list container for playlist parameters */ attr.i = 0; - str_list = string_list_new(); - if (!str_list) + if (!(str_list = string_list_new())) return 0; /* Copy playlist parameters into string list diff --git a/menu/cbs/menu_cbs_scan.c b/menu/cbs/menu_cbs_scan.c index 01ea18462c..47431fcfdb 100644 --- a/menu/cbs/menu_cbs_scan.c +++ b/menu/cbs/menu_cbs_scan.c @@ -56,8 +56,6 @@ int action_scan_file(const char *path, const char *directory_playlist = settings->paths.directory_playlist; const char *path_content_db = settings->paths.path_content_database; - fullpath[0] = '\0'; - menu_entries_get_last_stack(&menu_path, NULL, NULL, NULL, NULL); fill_pathname_join(fullpath, menu_path, path, sizeof(fullpath)); @@ -82,8 +80,6 @@ int action_scan_directory(const char *path, const char *directory_playlist = settings->paths.directory_playlist; const char *path_content_db = settings->paths.path_content_database; - fullpath[0] = '\0'; - menu_entries_get_last_stack(&menu_path, NULL, NULL, NULL, NULL); if (path) diff --git a/menu/cbs/menu_cbs_start.c b/menu/cbs/menu_cbs_start.c index de9d8e259e..2435ba16b0 100644 --- a/menu/cbs/menu_cbs_start.c +++ b/menu/cbs/menu_cbs_start.c @@ -625,8 +625,6 @@ static int action_start_core_lock( core_info_t *core_info = NULL; char msg[PATH_MAX_LENGTH]; - msg[0] = '\0'; - /* Need to fetch core name for error message */ /* If core is found, use display name */ @@ -686,8 +684,6 @@ static int action_start_core_set_standalone_exempt( core_info_t *core_info = NULL; char msg[PATH_MAX_LENGTH]; - msg[0] = '\0'; - /* Need to fetch core name for error message */ /* If core is found, use display name */ diff --git a/menu/cbs/menu_cbs_sublabel.c b/menu/cbs/menu_cbs_sublabel.c index e076eb0f15..13a656a167 100644 --- a/menu/cbs/menu_cbs_sublabel.c +++ b/menu/cbs/menu_cbs_sublabel.c @@ -76,8 +76,6 @@ static int menu_action_sublabel_file_browser_core(file_list_t *list, unsigned ty core_info->licenses_list) { char tmp[MENU_SUBLABEL_MAX_LENGTH]; - tmp[0] = '\0'; - /* Add license text */ string_list_join_concat(tmp, sizeof(tmp), core_info->licenses_list, ", "); @@ -172,13 +170,9 @@ static int menu_action_sublabel_contentless_core(file_list_t *list, { size_t n = 0; char tmp[64]; + tmp[0 ] = '\n'; if (display_licenses) - { - tmp[0 ] = '\n'; tmp[1 ] = '\0'; - } - else - tmp[0] = '\0'; n = strlcat(tmp, entry->runtime.runtime_str, sizeof(tmp)); if (n < 64 - 1) @@ -1310,8 +1304,6 @@ static int action_bind_sublabel_subsystem_load( unsigned j = 0; char buf[4096]; - buf[0] = '\0'; - for (j = 0; j < content_get_subsystem_rom_id(); j++) { strlcat(buf, " ", sizeof(buf)); @@ -1842,8 +1834,6 @@ static int action_bind_sublabel_core_updater_entry( entry->licenses_list) { char tmp[MENU_SUBLABEL_MAX_LENGTH]; - tmp[0] = '\0'; - /* Add license text */ string_list_join_concat(tmp, sizeof(tmp), entry->licenses_list, ", "); diff --git a/menu/menu_contentless_cores.c b/menu/menu_contentless_cores.c index 811f9ba521..5734d98575 100644 --- a/menu/menu_contentless_cores.c +++ b/menu/menu_contentless_cores.c @@ -131,9 +131,6 @@ static void contentless_cores_init_info_entries( if (core_info->licenses_list) { char tmp_str[MENU_SUBLABEL_MAX_LENGTH - 2]; - - tmp_str[0] = '\0'; - string_list_join_concat(tmp_str, sizeof(tmp_str), core_info->licenses_list, ", "); snprintf(licenses_str, sizeof(licenses_str), "%s: %s", @@ -268,7 +265,6 @@ static void contentless_cores_load_icons(contentless_cores_state_t *state) size_t i; icon_directory[0] = '\0'; - icon_path[0] = '\0'; if (!state) return;