From 38ff475d9e5d5d8936fd39cbb33b86d57c84575a Mon Sep 17 00:00:00 2001 From: Pablo Curiel Date: Sat, 13 Jan 2024 21:25:02 +0100 Subject: [PATCH] title: handle NACPs with empty language entries. Leftover ns application records for factory software yield NACP structs with no identifying strings. I wasn't expecting this to be a thing. --- source/core/title.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/source/core/title.c b/source/core/title.c index 80ea88f..b03879e 100644 --- a/source/core/title.c +++ b/source/core/title.c @@ -1326,7 +1326,7 @@ static bool titleReallocateApplicationMetadata(u32 extra_app_count, bool is_syst { if (cur_app_metadata->icon) free(cur_app_metadata->icon); free(cur_app_metadata); - cur_app_metadata = NULL; + cached_app_metadata[cached_app_metadata_count + i] = NULL; } } } @@ -1342,7 +1342,7 @@ static bool titleReallocateApplicationMetadata(u32 extra_app_count, bool is_syst tmp_app_metadata = NULL; /* Clear new application metadata pointer array area (if needed). */ - if (!free_entries && extra_app_count) memset(cached_app_metadata + cached_app_metadata_count, 0, extra_app_count * sizeof(TitleApplicationMetadata*)); + if (realloc_app_count > cached_app_metadata_count) memset(cached_app_metadata + cached_app_metadata_count, 0, extra_app_count * sizeof(TitleApplicationMetadata*)); } else { LOG_MSG_ERROR("Failed to reallocate application metadata pointer array! (%u element[s]).", realloc_app_count); goto end; @@ -1542,7 +1542,7 @@ static bool titleReallocateTitleInfoFromStorage(TitleStorage *title_storage, u32 { if (cur_title_info->content_infos) free(cur_title_info->content_infos); free(cur_title_info); - cur_title_info = NULL; + title_info[title_count + i] = NULL; } } } @@ -1558,7 +1558,7 @@ static bool titleReallocateTitleInfoFromStorage(TitleStorage *title_storage, u32 tmp_title_info = NULL; /* Clear new title info pointer array area (if needed). */ - if (!free_entries && extra_title_count) memset(title_info + title_count, 0, extra_title_count * sizeof(TitleInfo*)); + if (realloc_title_count > title_count) memset(title_info + title_count, 0, extra_title_count * sizeof(TitleInfo*)); } else { LOG_MSG_ERROR("Failed to reallocate title info pointer array! (%u element[s]).", realloc_title_count); goto end; @@ -1870,9 +1870,17 @@ static bool titleRetrieveUserApplicationMetadataByTitleId(u64 title_id, TitleApp /* Copy data. */ out->title_id = title_id; - memcpy(&(out->lang_entry), lang_entry, sizeof(NacpLanguageEntry)); - utilsTrimString(out->lang_entry.name); - utilsTrimString(out->lang_entry.author); + if (lang_entry) + { + memcpy(&(out->lang_entry), lang_entry, sizeof(NacpLanguageEntry)); + utilsTrimString(out->lang_entry.name); + utilsTrimString(out->lang_entry.author); + } else { + /* Yes, this can happen -- NACPs with empty language entries are a thing, somehow. */ + sprintf(out->lang_entry.name, "Unknown"); + sprintf(out->lang_entry.author, "Unknown"); + LOG_DATA_DEBUG(&(g_nsAppControlData->nacp), sizeof(NacpStruct), "NACP dump (ID %016lX):", title_id); + } out->icon_size = icon_size; out->icon = icon;