From 004e4b411d76d50c076ded609efc12fe79fcca67 Mon Sep 17 00:00:00 2001 From: Jean-Paul Mari Date: Tue, 23 Aug 2022 15:13:22 -0400 Subject: [PATCH] Fix crash with ELF format crc32 check --- jiffi2.txt | 4 ++++ src/format.cpp | 21 +++++++++++++++++++++ src/version.h | 2 +- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/jiffi2.txt b/jiffi2.txt index 089befa..40c1d22 100644 --- a/jiffi2.txt +++ b/jiffi2.txt @@ -11,6 +11,10 @@ Supported formats of the Atari Jaguar. - ROM +Version 1.0.1 - 08-23-2022 +- Fix crash with ELF format crc32 check. + + Version 1.0.0 - 02-28-2021 - Work based on JiFFI v1.43 which is based on the v1.42, written in GFA Basic, released by ggn. -- Follow the same set of features diff --git a/src/format.cpp b/src/format.cpp index e0a153e..3d03262 100644 --- a/src/format.cpp +++ b/src/format.cpp @@ -218,6 +218,7 @@ int detect_file_format(void) //ElfMem = (Elf*)ptr; if (((((((Elf32_Ehdr*)ptrload)->e_machine) & 0xFF) == EM_68K) && ((((Elf32_Ehdr*)ptrload)->e_type) == ET_EXEC)) || (!endianess && (((((Elf32_Ehdr*)ptrload)->e_machine) & 0xFF00) == (EM_68K << 8)) && ((((Elf32_Ehdr*)ptrload)->e_type) == (ET_EXEC << 8)))) { + unsigned char* ptr = NULL; size_t NbrSect; Elf* ElfMem = elf_memory((char*)ptrload, linj); if (!elf_getshdrnum(ElfMem, &NbrSect)) @@ -235,22 +236,42 @@ int detect_file_format(void) PtrGElfShdr = gelf_getshdr(PtrElfScn, &GElfShdr); switch (PtrGElfShdr->sh_type) { + // Program data case SHT_PROGBITS: if ((PtrGElfShdr->sh_flags & (SHF_ALLOC | SHF_WRITE | SHF_EXECINSTR))) { if (PtrGElfShdr->sh_addr < loadadr) { loadadr = PtrGElfShdr->sh_addr; + if (ptr < (ptrload + PtrGElfShdr->sh_offset)) + { + ptr = (ptrload + PtrGElfShdr->sh_offset); + } } } + else + { + linj -= PtrGElfShdr->sh_size; + } break; + // Symbol table + case SHT_SYMTAB: + // String table + case SHT_STRTAB: + // Section header table entry unused + case SHT_NULL: + // Program space with no data (bss) + case SHT_NOBITS: + // reduce the size with the section's size default: + linj -= PtrGElfShdr->sh_size; break; } } // get run address //runadr = !endianess ? (uint32_t)PtrGElfEhdr->e_entry : ((((uint32_t)PtrGElfEhdr->e_entry & 0xff000000) >> 24) | (((uint32_t)PtrGElfEhdr->e_entry & 0x00ff0000) >> 8) | (((uint32_t)PtrGElfEhdr->e_entry & 0x0000ff00) << 8) | (((uint32_t)PtrGElfEhdr->e_entry & 0x000000ff) << 24)); runadr = (uint32_t)PtrGElfEhdr->e_entry; + memcpy(imageadr, ptr, linj); detected_format = format_ELF; } } diff --git a/src/version.h b/src/version.h index 729bca5..ec921f0 100644 --- a/src/version.h +++ b/src/version.h @@ -5,6 +5,6 @@ // Release Information #define MAJOR 1 // Major version number #define MINOR 0 // Minor version number -#define PATCH 0 // Patch release number +#define PATCH 1 // Patch release number #endif // __VERSION_H__