From fa80ec099f39162c1c4d66beb59dbd0771411d6e Mon Sep 17 00:00:00 2001 From: libretroadmin Date: Tue, 20 Jun 2023 13:21:26 +0200 Subject: [PATCH] Rewrite some strlcat calls to strlcpy --- menu/drivers/materialui.c | 33 ++++++++++++++--------- menu/menu_displaylist.c | 57 +++++++++++++++++++++------------------ menu/menu_explore.c | 10 ++++--- menu/menu_setting.c | 2 +- tasks/task_decompress.c | 42 ++++++++++++++++------------- 5 files changed, 81 insertions(+), 63 deletions(-) diff --git a/menu/drivers/materialui.c b/menu/drivers/materialui.c index 5964c1ea2f..92ab88d251 100644 --- a/menu/drivers/materialui.c +++ b/menu/drivers/materialui.c @@ -3392,6 +3392,7 @@ static bool materialui_render_process_entry_playlist_desktop( if (mui->status_bar.delay_timer > mui->thumbnail_stream_delay) { + size_t _len; settings_t *settings = config_get_ptr(); bool content_runtime_log = settings->bools.content_runtime_log; bool content_runtime_log_aggregate = settings->bools.content_runtime_log_aggregate; @@ -3462,21 +3463,27 @@ static bool materialui_render_process_entry_playlist_desktop( last_played_str = mui->status_bar.last_played_fallback_str; /* Generate metadata string */ - strlcpy(mui->status_bar.str, + _len = strlcpy(mui->status_bar.str, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_PLAYLIST_SUBLABEL_CORE), sizeof(mui->status_bar.str)); - strlcat(mui->status_bar.str, " ", - sizeof(mui->status_bar.str)); - strlcat(mui->status_bar.str, core_name, - sizeof(mui->status_bar.str)); - strlcat(mui->status_bar.str, MUI_TICKER_SPACER, - sizeof(mui->status_bar.str)); - strlcat(mui->status_bar.str, runtime_str, - sizeof(mui->status_bar.str)); - strlcat(mui->status_bar.str, MUI_TICKER_SPACER, - sizeof(mui->status_bar.str)); - strlcat(mui->status_bar.str, last_played_str, - sizeof(mui->status_bar.str)); + _len += strlcpy(mui->status_bar.str + _len, + " ", + sizeof(mui->status_bar.str) - _len); + _len += strlcpy(mui->status_bar.str + _len, + core_name, + sizeof(mui->status_bar.str) - _len); + _len += strlcpy(mui->status_bar.str + _len, + MUI_TICKER_SPACER, + sizeof(mui->status_bar.str) - _len); + _len += strlcpy(mui->status_bar.str + _len, + runtime_str, + sizeof(mui->status_bar.str) - _len); + _len += strlcpy(mui->status_bar.str + _len, + MUI_TICKER_SPACER, + sizeof(mui->status_bar.str) - _len); + _len += strlcpy(mui->status_bar.str + _len, + last_played_str, + sizeof(mui->status_bar.str) - _len); /* All metadata is cached */ mui->status_bar.cached = true; diff --git a/menu/menu_displaylist.c b/menu/menu_displaylist.c index eea4026b3f..55be2a6cda 100644 --- a/menu/menu_displaylist.c +++ b/menu/menu_displaylist.c @@ -1535,17 +1535,17 @@ static unsigned menu_displaylist_parse_supported_cores(menu_displaylist_info_t * * to the displaylist */ if (core_is_pending) { - size_t _len; char entry_alt_text[256]; - _len = strlcpy(entry_alt_text, detect_core_str, + size_t _len = strlcpy(entry_alt_text, detect_core_str, sizeof(entry_alt_text)); entry_alt_text[_len ] = ' '; - entry_alt_text[_len+1] = '('; - entry_alt_text[_len+2] = '\0'; - _len = strlcat(entry_alt_text, - pending_core_name, sizeof(entry_alt_text)); + entry_alt_text[++_len] = '('; + entry_alt_text[++_len] = '\0'; + _len += strlcpy(entry_alt_text + _len, + pending_core_name, + sizeof(entry_alt_text) - _len); entry_alt_text[_len ] = ')'; - entry_alt_text[_len+1] = '\0'; + entry_alt_text[++_len] = '\0'; menu_entries_prepend(info->list, pending_core_path, msg_hash_to_str(current_core_enum_label), @@ -6386,24 +6386,28 @@ static unsigned menu_displaylist_netplay_refresh_rooms(file_list_t *list) { if (!show_passworded) continue; - _len = strlcpy(passworded, "[", sizeof(passworded)); - strlcpy(passworded + _len, msg_room_pwd, sizeof(passworded) - _len); - strlcat(passworded, "] ", sizeof(passworded)); + _len = strlcpy(passworded, "[", + sizeof(passworded)); + _len += strlcpy(passworded + _len, + msg_room_pwd, + sizeof(passworded) - _len); + _len += strlcpy(passworded + _len, "] ", + sizeof(passworded) - _len); } else *passworded = '\0'; - _len = strlcpy(buf, passworded, sizeof(buf)); - strlcpy(buf + _len, room_type, sizeof(buf) - _len); - strlcat(buf, ": ", sizeof(buf)); - strlcat(buf, room->nickname, sizeof(buf)); + _len = strlcpy(buf, passworded, sizeof(buf)); + _len += strlcpy(buf + _len, room_type, sizeof(buf) - _len); + _len += strlcpy(buf + _len, ": ", sizeof(buf) - _len); + _len += strlcpy(buf + _len, room->nickname, sizeof(buf) - _len); if (!room->lan && !string_is_empty(room->country)) { - _len = strlcpy(country, " (", sizeof(country)); - strlcpy(country + _len, room->country, sizeof(country) - _len); - strlcat(country, ")", sizeof(country)); - strlcat(buf, country, sizeof(buf)); + size_t _len2 = strlcpy(country, " (", sizeof(country)); + _len2 += strlcpy(country + _len2, room->country, sizeof(country) - _len2); + _len2 += strlcpy(country + _len2, ")", sizeof(country) - _len2); + strlcpy(buf + _len, country, sizeof(buf) - _len); } else *country = '\0'; @@ -11647,8 +11651,8 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, size_t _len = strlcpy(serial, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_RDB_ENTRY_SERIAL), sizeof(serial)); - strlcpy(serial + _len, "#: ", sizeof(serial) - _len); - strlcat(serial, cd_info.serial, sizeof(serial)); + _len += strlcpy(serial + _len, "#: ", sizeof(serial) - _len); + strlcpy(serial + _len, cd_info.serial, sizeof(serial) - _len); if (menu_entries_append(info->list, serial, @@ -11961,6 +11965,7 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, #if defined(HAVE_LAKKA_SWITCH) || defined(HAVE_LIBNX) case DISPLAYLIST_SWITCH_CPU_PROFILE: { + size_t _len; unsigned i; char text[PATH_MAX_LENGTH]; #ifdef HAVE_LAKKA_SWITCH @@ -11977,11 +11982,10 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, fgets(current_profile, PATH_MAX_LENGTH, profile); pclose(profile); /* TODO/FIXME - localize */ - strlcpy(text, "Current profile: ", sizeof(text)); - strlcat(text, current_profile, sizeof(text)); + _len = strlcpy(text, "Current profile: ", sizeof(text)); + strlcpy(text + _len, current_profile, sizeof(text) - _len); #else { - size_t _len; u32 currentClock = 0; if (hosversionBefore(8, 0, 0)) pcvGetClockRate(PcvModule_CpuBus, ¤tClock); @@ -12022,6 +12026,7 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, #if defined(HAVE_LAKKA_SWITCH) case DISPLAYLIST_SWITCH_GPU_PROFILE: { + size_t _len; unsigned i; char text[PATH_MAX_LENGTH]; char current_profile[PATH_MAX_LENGTH]; @@ -12038,8 +12043,8 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, menu_entries_clear(info->list); /* TODO/FIXME - Localize */ - strlcpy(text, "Current profile : ", sizeof(text)); - strlcat(text, current_profile, sizeof(text)); + _len = strlcpy(text, "Current profile : ", sizeof(text)); + strlcpy(text + _len, current_profile, sizeof(text) - _len); if (menu_entries_append(info->list, text, "", 0, MENU_INFO_MESSAGE, 0, 0, NULL)) count++; @@ -12049,7 +12054,7 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, char title[PATH_MAX_LENGTH]; char* profile = SWITCH_GPU_PROFILES[i]; char* speed = SWITCH_GPU_SPEEDS[i]; - size_t _len = strlcpy(title, profile, sizeof(title)); + _len = strlcpy(title, profile, sizeof(title)); snprintf(title + _len, sizeof(title) - _len, " (%s)", speed); if (menu_entries_append(info->list, title, "", 0, MENU_SET_SWITCH_GPU_PROFILE, 0, i, NULL)) diff --git a/menu/menu_explore.c b/menu/menu_explore.c index 455f0020ee..39a048e186 100644 --- a/menu/menu_explore.c +++ b/menu/menu_explore.c @@ -426,10 +426,11 @@ static void explore_load_icons(explore_state_t *state) for (i = 0; i != system_count; i++) { struct texture_image ti; - - strlcpy(path + pathlen, - state->by[EXPLORE_BY_SYSTEM][i]->str, sizeof(path) - pathlen); - strlcat(path, ".png", sizeof(path)); + size_t _len = pathlen; + _len += strlcpy(path + pathlen, + state->by[EXPLORE_BY_SYSTEM][i]->str, + sizeof(path) - pathlen); + strlcpy(path + _len, ".png", sizeof(path) - _len); if (!path_is_valid(path)) continue; @@ -1052,6 +1053,7 @@ static int explore_action_ok_deleteview(const char *path, const char *label, uns static void explore_action_saveview_complete(void *userdata, const char *name) { + size_t _len; int count = 0, op; char lvwpath[PATH_MAX_LENGTH]; intfstream_t *file; diff --git a/menu/menu_setting.c b/menu/menu_setting.c index d83d41fef5..1e62e50984 100644 --- a/menu/menu_setting.c +++ b/menu/menu_setting.c @@ -9161,7 +9161,7 @@ static bool setting_append_list_input_player_options( label[_len+1] = '\0'; } else - label[0] = '\0'; + label[0] = '\0'; if ( settings->bools.input_descriptor_label_show diff --git a/tasks/task_decompress.c b/tasks/task_decompress.c index d0d39d0e77..d7510e89bc 100644 --- a/tasks/task_decompress.c +++ b/tasks/task_decompress.c @@ -72,14 +72,16 @@ static int file_decompressed_subdir(const char *name, error: userdata->dec->callback_error = (char*)malloc(CALLBACK_ERROR_SIZE); - strlcpy(userdata->dec->callback_error, "Failed to deflate ", - CALLBACK_ERROR_SIZE); - _len = strlcat( - userdata->dec->callback_error, - path, CALLBACK_ERROR_SIZE); - userdata->dec->callback_error[_len ] = '.'; - userdata->dec->callback_error[_len+1] = '\n'; - userdata->dec->callback_error[_len+2] = '\0'; + _len = strlcpy(userdata->dec->callback_error, + "Failed to deflate ", + CALLBACK_ERROR_SIZE); + _len += strlcpy( + userdata->dec->callback_error + _len, + path, + CALLBACK_ERROR_SIZE - _len); + userdata->dec->callback_error[ _len] = '.'; + userdata->dec->callback_error[++_len] = '\n'; + userdata->dec->callback_error[++_len] = '\0'; return 0; } @@ -113,13 +115,13 @@ static int file_decompressed(const char *name, const char *valid_exts, error: dec->callback_error = (char*)malloc(CALLBACK_ERROR_SIZE); - strlcpy(dec->callback_error, "Failed to deflate ", + _len = strlcpy(dec->callback_error, "Failed to deflate ", CALLBACK_ERROR_SIZE); - _len = strlcat(dec->callback_error, - path, CALLBACK_ERROR_SIZE); - dec->callback_error[_len ] = '.'; - dec->callback_error[_len+1] = '\n'; - dec->callback_error[_len+2] = '\0'; + _len += strlcpy(dec->callback_error + _len, + path, CALLBACK_ERROR_SIZE - _len); + dec->callback_error[ _len] = '.'; + dec->callback_error[++_len] = '\n'; + dec->callback_error[++_len] = '\0'; return 0; } @@ -339,12 +341,14 @@ void *task_push_decompress( _len = strlcpy(tmp, msg_hash_to_str(MSG_EXTRACTING), sizeof(tmp)); - tmp[_len ] = ' '; - tmp[_len+1] = '\''; - tmp[_len+2] = '\0'; - _len = strlcat(tmp, path_basename(source_file), sizeof(tmp)); + tmp[ _len] = ' '; + tmp[++_len] = '\''; + tmp[++_len] = '\0'; + _len += strlcpy(tmp + _len, + path_basename(source_file), + sizeof(tmp) - _len); tmp[_len ] = '\''; - tmp[_len+1] = '\0'; + tmp[++_len] = '\0'; t->title = strdup(tmp); t->mute = mute;