Skip to content

Commit

Permalink
title: handle NACPs with empty language entries.
Browse files Browse the repository at this point in the history
Leftover ns application records for factory software yield NACP structs with no identifying strings.

I wasn't expecting this to be a thing.
  • Loading branch information
DarkMatterCore committed Jan 13, 2024
1 parent 62c2930 commit 38ff475
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions source/core/title.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
}
}
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 38ff475

Please sign in to comment.