From f71ad5ac2c44861c6b88bc8a292614c94e839020 Mon Sep 17 00:00:00 2001 From: hexkyz Date: Tue, 14 Jul 2020 18:58:19 +0100 Subject: [PATCH] fusee/sept: ensure proper array initialization in exception handling --- fusee/fusee-primary/src/exception_handlers.c | 14 +++++++------- fusee/fusee-secondary/src/exception_handlers.c | 14 +++++++------- sept/sept-secondary/src/exception_handlers.c | 14 +++++++------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/fusee/fusee-primary/src/exception_handlers.c b/fusee/fusee-primary/src/exception_handlers.c index 6a005293a..128425891 100644 --- a/fusee/fusee-primary/src/exception_handlers.c +++ b/fusee/fusee-primary/src/exception_handlers.c @@ -38,7 +38,7 @@ static const char *register_names[] = { /* Adapted from https://gist.github.com/ccbrown/9722406 */ static void hexdump(const void* data, size_t size, uintptr_t addrbase, char* strbuf) { const uint8_t *d = (const uint8_t *)data; - char ascii[17]; + char ascii[17] = {0}; ascii[16] = '\0'; for (size_t i = 0; i < size; i++) { @@ -79,17 +79,17 @@ void setup_exception_handlers(void) { } void exception_handler_main(uint32_t *registers, unsigned int exception_type) { - char exception_log[0x400]; - uint8_t code_dump[CODE_DUMP_SIZE]; - uint8_t stack_dump[STACK_DUMP_SIZE]; - size_t code_dump_size; - size_t stack_dump_size; + char exception_log[0x400] = {0}; + uint8_t code_dump[CODE_DUMP_SIZE] = {0}; + uint8_t stack_dump[STACK_DUMP_SIZE] = {0}; + size_t code_dump_size = 0; + size_t stack_dump_size = 0; uint32_t pc = registers[15]; uint32_t cpsr = registers[16]; uint32_t instr_addr = pc + ((cpsr & 0x20) ? 2 : 4) - CODE_DUMP_SIZE; - sprintf(exception_log + strlen(exception_log), "An exception occured!\n"); + sprintf(exception_log, "An exception occured!\n"); code_dump_size = safecpy(code_dump, (const void *)instr_addr, CODE_DUMP_SIZE); stack_dump_size = safecpy(stack_dump, (const void *)registers[13], STACK_DUMP_SIZE); diff --git a/fusee/fusee-secondary/src/exception_handlers.c b/fusee/fusee-secondary/src/exception_handlers.c index b09f5507c..5ade0ba66 100644 --- a/fusee/fusee-secondary/src/exception_handlers.c +++ b/fusee/fusee-secondary/src/exception_handlers.c @@ -39,7 +39,7 @@ static const char *register_names[] = { /* Adapted from https://gist.github.com/ccbrown/9722406 */ static void hexdump(const void* data, size_t size, uintptr_t addrbase, char* strbuf) { const uint8_t *d = (const uint8_t *)data; - char ascii[17]; + char ascii[17] = {0}; ascii[16] = '\0'; for (size_t i = 0; i < size; i++) { @@ -80,17 +80,17 @@ void setup_exception_handlers(void) { } void exception_handler_main(uint32_t *registers, unsigned int exception_type) { - char exception_log[0x400]; - uint8_t code_dump[CODE_DUMP_SIZE]; - uint8_t stack_dump[STACK_DUMP_SIZE]; - size_t code_dump_size; - size_t stack_dump_size; + char exception_log[0x400] = {0}; + uint8_t code_dump[CODE_DUMP_SIZE] = {0}; + uint8_t stack_dump[STACK_DUMP_SIZE] = {0}; + size_t code_dump_size = 0; + size_t stack_dump_size = 0; uint32_t pc = registers[15]; uint32_t cpsr = registers[16]; uint32_t instr_addr = pc + ((cpsr & 0x20) ? 2 : 4) - CODE_DUMP_SIZE; - sprintf(exception_log + strlen(exception_log), "An exception occured!\n"); + sprintf(exception_log, "An exception occured!\n"); code_dump_size = safecpy(code_dump, (const void *)instr_addr, CODE_DUMP_SIZE); stack_dump_size = safecpy(stack_dump, (const void *)registers[13], STACK_DUMP_SIZE); diff --git a/sept/sept-secondary/src/exception_handlers.c b/sept/sept-secondary/src/exception_handlers.c index 6a005293a..128425891 100644 --- a/sept/sept-secondary/src/exception_handlers.c +++ b/sept/sept-secondary/src/exception_handlers.c @@ -38,7 +38,7 @@ static const char *register_names[] = { /* Adapted from https://gist.github.com/ccbrown/9722406 */ static void hexdump(const void* data, size_t size, uintptr_t addrbase, char* strbuf) { const uint8_t *d = (const uint8_t *)data; - char ascii[17]; + char ascii[17] = {0}; ascii[16] = '\0'; for (size_t i = 0; i < size; i++) { @@ -79,17 +79,17 @@ void setup_exception_handlers(void) { } void exception_handler_main(uint32_t *registers, unsigned int exception_type) { - char exception_log[0x400]; - uint8_t code_dump[CODE_DUMP_SIZE]; - uint8_t stack_dump[STACK_DUMP_SIZE]; - size_t code_dump_size; - size_t stack_dump_size; + char exception_log[0x400] = {0}; + uint8_t code_dump[CODE_DUMP_SIZE] = {0}; + uint8_t stack_dump[STACK_DUMP_SIZE] = {0}; + size_t code_dump_size = 0; + size_t stack_dump_size = 0; uint32_t pc = registers[15]; uint32_t cpsr = registers[16]; uint32_t instr_addr = pc + ((cpsr & 0x20) ? 2 : 4) - CODE_DUMP_SIZE; - sprintf(exception_log + strlen(exception_log), "An exception occured!\n"); + sprintf(exception_log, "An exception occured!\n"); code_dump_size = safecpy(code_dump, (const void *)instr_addr, CODE_DUMP_SIZE); stack_dump_size = safecpy(stack_dump, (const void *)registers[13], STACK_DUMP_SIZE);