From 7003070a0ec2acbbfc0be793765a331889f8cb8f Mon Sep 17 00:00:00 2001 From: d0k3 Date: Mon, 6 Jun 2016 16:34:30 +0200 Subject: [PATCH] Prevent infinite loop with certain SD formatting --- source/decryptor/nand.c | 2 ++ source/decryptor/nand.h | 4 ---- source/fs.c | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/source/decryptor/nand.c b/source/decryptor/nand.c index c942923..34b365f 100644 --- a/source/decryptor/nand.c +++ b/source/decryptor/nand.c @@ -81,6 +81,8 @@ u32 CheckEmuNand(void) // check the MBR for presence of a hidden partition u32 hidden_sectors = NumHiddenSectors(); + if (hidden_sectors > 4 * multi_sectors) + hidden_sectors = 4 * multi_sectors; for (u32 offset_sector = 0; offset_sector + nand_size_sectors_min <= hidden_sectors; offset_sector += multi_sectors) { // check for RedNAND type EmuNAND diff --git a/source/decryptor/nand.h b/source/decryptor/nand.h index 79b0994..fe1b113 100644 --- a/source/decryptor/nand.h +++ b/source/decryptor/nand.h @@ -13,9 +13,6 @@ #define P_FIRM1 (1<<4) #define P_CTRNAND (1<<5) -// force slot 0x04 for CTRNAND padgen -#define PG_FORCESLOT4 (1<<0) - // options for NAND backup & restore #define NB_MINSIZE (1<<10) #define NR_NOCHECKS (1<<11) @@ -53,7 +50,6 @@ u32 InputFileNameSelector(char* filename, const char* basename, char* extension, u32 DecryptNandToMem(u8* buffer, u32 offset, u32 size, PartitionInfo* partition); u32 DecryptNandToFile(const char* filename, u32 offset, u32 size, PartitionInfo* partition); -u32 DecryptNandToHash(u8* hash, u32 offset, u32 size, PartitionInfo* partition); u32 EncryptMemToNand(u8* buffer, u32 offset, u32 size, PartitionInfo* partition); u32 EncryptFileToNand(const char* filename, u32 offset, u32 size, PartitionInfo* partition); diff --git a/source/fs.c b/source/fs.c index 3c5f58c..3c8d34e 100644 --- a/source/fs.c +++ b/source/fs.c @@ -394,5 +394,5 @@ uint64_t TotalStorageSpace() uint32_t NumHiddenSectors() { - return (uint32_t) fs.volbase - 1; + return (fs.volbase > 0) ? (uint32_t) fs.volbase - 1 : 0; }