Fixed inability to install a larger/smaller ticket when a smaller/large one is installed (#733)

* Fixed inability to install a larger ticket when a smaller one is installed

* improved AddBDRIEntry checks, formatting and added define for REPLACE_SIZE_MISMATCH
This commit is contained in:
TimmSkiller 2021-10-23 14:19:13 +03:00 committed by GitHub
parent 0dbe70928f
commit 55385a5502
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,6 +2,7 @@
#include "vff.h"
#define FAT_ENTRY_SIZE 2 * sizeof(u32)
#define REPLACE_SIZE_MISMATCH 2
#define getfatflag(uv) (((uv) & 0x80000000UL) != 0)
#define getfatindex(uv) ((uv) & 0x7FFFFFFFUL)
@ -369,7 +370,8 @@ static u32 AddBDRIEntry(const BDRIFsHeader* fs_header, const u32 fs_header_offse
// If an entry for the tid already existed that is already the specified size and replace was specified, just replace the existing entry
if (memcmp(title_id_be, file_entry.title_id, 8) == 0) {
if (!replace || (file_entry.size != size)) return 1;
if (!replace) return 1;
else if (file_entry.size != size) return REPLACE_SIZE_MISMATCH;
else {
do_replace = true;
break;
@ -864,10 +866,15 @@ u32 AddTicketToDB(const char* path, const u8* title_id, const Ticket* ticket, bo
bdrifp = &file;
u32 add_bdri_res = 0;
if ((BDRIRead(0, sizeof(TickDBPreHeader), &pre_header) != FR_OK) ||
!CheckDBMagic((u8*) &pre_header, true) ||
((add_bdri_res = AddBDRIEntry(&(pre_header.fs_header), sizeof(TickDBPreHeader) - sizeof(BDRIFsHeader), title_id,
(const u8*) te, entry_size, replace)) == 1) ||
(add_bdri_res == REPLACE_SIZE_MISMATCH && ((RemoveBDRIEntry(&(pre_header.fs_header), sizeof(TickDBPreHeader) - sizeof(BDRIFsHeader), title_id) != 0) ||
(AddBDRIEntry(&(pre_header.fs_header), sizeof(TickDBPreHeader) - sizeof(BDRIFsHeader), title_id,
(const u8*) te, entry_size, replace) != 0)) {
(const u8*) te, entry_size, replace) != 0)))) {
free(te);
fvx_close(bdrifp);
bdrifp = NULL;