From cda2cedf4530271ad91baaa7c224b18cc192f65e Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Thu, 7 Nov 2024 04:04:10 +0000 Subject: [PATCH 1/2] Loader: Fix BusFault in handling of OOM --- lib/flipper_application/elf/elf_file.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/flipper_application/elf/elf_file.c b/lib/flipper_application/elf/elf_file.c index d0c4f52fb1f..2a9307cacc7 100644 --- a/lib/flipper_application/elf/elf_file.c +++ b/lib/flipper_application/elf/elf_file.c @@ -8,11 +8,11 @@ #define TAG "Elf" -#define ELF_NAME_BUFFER_LEN 32 -#define SECTION_OFFSET(e, n) ((e)->section_table + (n) * sizeof(Elf32_Shdr)) -#define IS_FLAGS_SET(v, m) (((v) & (m)) == (m)) +#define ELF_NAME_BUFFER_LEN 32 +#define SECTION_OFFSET(e, n) ((e)->section_table + (n) * sizeof(Elf32_Shdr)) +#define IS_FLAGS_SET(v, m) (((v) & (m)) == (m)) #define RESOLVER_THREAD_YIELD_STEP 30 -#define FAST_RELOCATION_VERSION 1 +#define FAST_RELOCATION_VERSION 1 // #define ELF_DEBUG_LOG 1 @@ -834,7 +834,9 @@ void elf_file_free(ELFFile* elf) { aligned_free(itref->value.data); } if(itref->value.fast_rel) { - aligned_free(itref->value.fast_rel->data); + if(itref->value.fast_rel->data) { + aligned_free(itref->value.fast_rel->data); + } free(itref->value.fast_rel); } free((void*)itref->key); From 0e24a202d7b041726d70e2f7b59249c029c2dd21 Mon Sep 17 00:00:00 2001 From: Aleksandr Kutuzov Date: Thu, 19 Dec 2024 06:18:27 +0900 Subject: [PATCH 2/2] Furi: fix crash in aligned_alloc, cleanup aligned_alloc use --- furi/core/memmgr.c | 4 +++- lib/flipper_application/elf/elf_file.c | 8 ++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/furi/core/memmgr.c b/furi/core/memmgr.c index d3ff873ae50..8ee0d1723b7 100644 --- a/furi/core/memmgr.c +++ b/furi/core/memmgr.c @@ -106,5 +106,7 @@ void* aligned_malloc(size_t size, size_t alignment) { } void aligned_free(void* p) { - free(((void**)p)[-1]); + if(p) { + free(((void**)p)[-1]); + } } diff --git a/lib/flipper_application/elf/elf_file.c b/lib/flipper_application/elf/elf_file.c index 2a9307cacc7..bd8ecdf7ef3 100644 --- a/lib/flipper_application/elf/elf_file.c +++ b/lib/flipper_application/elf/elf_file.c @@ -830,13 +830,9 @@ void elf_file_free(ELFFile* elf) { for(ELFSectionDict_it(it, elf->sections); !ELFSectionDict_end_p(it); ELFSectionDict_next(it)) { const ELFSectionDict_itref_t* itref = ELFSectionDict_cref(it); - if(itref->value.data) { - aligned_free(itref->value.data); - } + aligned_free(itref->value.data); if(itref->value.fast_rel) { - if(itref->value.fast_rel->data) { - aligned_free(itref->value.fast_rel->data); - } + aligned_free(itref->value.fast_rel->data); free(itref->value.fast_rel); } free((void*)itref->key);