From 6e5d4b8fc95cc16fa191b3715ebc71c4b6dd1920 Mon Sep 17 00:00:00 2001 From: TuxSH Date: Sun, 6 May 2018 00:45:30 +0200 Subject: [PATCH] Fix bss overflow error --- fusee/fusee-secondary/src/package2.c | 26 ++++++++++++++++++++---- fusee/fusee-secondary/src/stratosphere.c | 20 +++++++++++++++--- 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/fusee/fusee-secondary/src/package2.c b/fusee/fusee-secondary/src/package2.c index 8e8e6d0e7..25fb24877 100644 --- a/fusee/fusee-secondary/src/package2.c +++ b/fusee/fusee-secondary/src/package2.c @@ -1,4 +1,5 @@ #include +#include #include "utils.h" #include "masterkey.h" #include "stratosphere.h" @@ -8,10 +9,10 @@ /* Stage 2 executes from DRAM, so we have tons of space. */ /* This *greatly* simplifies logic. */ -unsigned char g_patched_package2[PACKAGE2_SIZE_MAX]; -unsigned char g_package2_sections[PACKAGE2_SECTION_MAX][PACKAGE2_SIZE_MAX]; +static uint8_t *g_patched_package2; +static uint8_t *g_package2_sections[PACKAGE2_SECTION_MAX]; -package2_header_t *g_patched_package2_header = (package2_header_t *)g_patched_package2; +static package2_header_t *g_patched_package2_header; void package2_decrypt(void *package2_address); void package2_add_thermosphere_section(void); @@ -19,6 +20,23 @@ void package2_patch_kernel(void); void package2_patch_ini1(void); void package2_fixup_header_and_section_hashes(void); +void package2_allocate_mem(void) { + /* TODO: call it */ + g_patched_package2 = (uint8_t *)malloc(PACKAGE2_SIZE_MAX); + for(size_t i = 0; i < PACKAGE2_SECTION_MAX; i++) { + g_package2_sections[i] = (uint8_t *)malloc(PACKAGE2_SIZE_MAX); + } + g_patched_package2_header = (package2_header_t *)g_patched_package2; +} + +void package2_free_mem(void) { + free(g_patched_package2); + for(size_t i = 0; i < PACKAGE2_SECTION_MAX; i++) { + free(g_package2_sections[i]); + } + g_patched_package2_header = NULL; +} + void package2_patch(void *package2_address) { /* First things first: Decrypt Package2. */ package2_decrypt(package2_address); @@ -36,7 +54,7 @@ void package2_patch(void *package2_address) { package2_fixup_header_and_section_hashes(); /* Relocate Package2. */ - memcpy(NX_BOOTLOADER_PACKAGE2_LOAD_ADDRESS, g_patched_package2, sizeof(g_patched_package2)); + memcpy(NX_BOOTLOADER_PACKAGE2_LOAD_ADDRESS, g_patched_package2, PACKAGE2_SIZE_MAX); } static void package2_crypt_ctr(unsigned int master_key_rev, void *dst, size_t dst_size, const void *src, size_t src_size, const void *ctr, size_t ctr_size) { diff --git a/fusee/fusee-secondary/src/stratosphere.c b/fusee/fusee-secondary/src/stratosphere.c index 095abab81..417632ee0 100644 --- a/fusee/fusee-secondary/src/stratosphere.c +++ b/fusee/fusee-secondary/src/stratosphere.c @@ -1,13 +1,27 @@ #include +#include +#include #include "utils.h" #include "package2.h" #include "stratosphere.h" #include "sd_utils.h" -unsigned char g_stratosphere_ini1[PACKAGE2_SIZE_MAX]; +static uint8_t *g_stratosphere_ini1; static bool g_initialized_stratosphere_ini1 = false; -unsigned char g_ini1_buffer[PACKAGE2_SIZE_MAX]; +static uint8_t *g_ini1_buffer; + +void stratosphere_allocate_mem(void) { + /* TODO call it*/ + g_stratosphere_ini1 = (uint8_t *)malloc(PACKAGE2_SIZE_MAX); + g_ini1_buffer = (uint8_t *)malloc(PACKAGE2_SIZE_MAX); +} + +void stratosphere_free_mem(void) { + /* TODO call it*/ + free(g_stratosphere_ini1); + free(g_ini1_buffer); +} ini1_header_t *stratosphere_get_ini1(void) { ini1_header_t *ini1_header = (ini1_header_t *)g_stratosphere_ini1; @@ -38,7 +52,7 @@ size_t stratosphere_merge_inis(void *dst, ini1_header_t **inis, unsigned int num uint64_t process_list[INI1_MAX_KIPS] = {0}; - memset(g_ini1_buffer, 0, sizeof(g_ini1_buffer)); + memset(g_ini1_buffer, 0, PACKAGE2_SIZE_MAX); ini1_header_t *merged = (ini1_header_t *)g_ini1_buffer; merged->magic = MAGIC_INI1; merged->num_processes = 0;