Skip to content

Commit 004e4b4

Browse files
committed
Fix crash with ELF format crc32 check
1 parent 080ab2e commit 004e4b4

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

jiffi2.txt

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ Supported formats of the Atari Jaguar.
1111
- ROM
1212

1313

14+
Version 1.0.1 - 08-23-2022
15+
- Fix crash with ELF format crc32 check.
16+
17+
1418
Version 1.0.0 - 02-28-2021
1519
- Work based on JiFFI v1.43 which is based on the v1.42, written in GFA Basic, released by ggn.
1620
-- Follow the same set of features

src/format.cpp

+21
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ int detect_file_format(void)
218218
//ElfMem = (Elf*)ptr;
219219
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))))
220220
{
221+
unsigned char* ptr = NULL;
221222
size_t NbrSect;
222223
Elf* ElfMem = elf_memory((char*)ptrload, linj);
223224
if (!elf_getshdrnum(ElfMem, &NbrSect))
@@ -235,22 +236,42 @@ int detect_file_format(void)
235236
PtrGElfShdr = gelf_getshdr(PtrElfScn, &GElfShdr);
236237
switch (PtrGElfShdr->sh_type)
237238
{
239+
// Program data
238240
case SHT_PROGBITS:
239241
if ((PtrGElfShdr->sh_flags & (SHF_ALLOC | SHF_WRITE | SHF_EXECINSTR)))
240242
{
241243
if (PtrGElfShdr->sh_addr < loadadr)
242244
{
243245
loadadr = PtrGElfShdr->sh_addr;
246+
if (ptr < (ptrload + PtrGElfShdr->sh_offset))
247+
{
248+
ptr = (ptrload + PtrGElfShdr->sh_offset);
249+
}
244250
}
245251
}
252+
else
253+
{
254+
linj -= PtrGElfShdr->sh_size;
255+
}
246256
break;
257+
// Symbol table
258+
case SHT_SYMTAB:
259+
// String table
260+
case SHT_STRTAB:
261+
// Section header table entry unused
262+
case SHT_NULL:
263+
// Program space with no data (bss)
264+
case SHT_NOBITS:
265+
// reduce the size with the section's size
247266
default:
267+
linj -= PtrGElfShdr->sh_size;
248268
break;
249269
}
250270
}
251271
// get run address
252272
//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));
253273
runadr = (uint32_t)PtrGElfEhdr->e_entry;
274+
memcpy(imageadr, ptr, linj);
254275
detected_format = format_ELF;
255276
}
256277
}

src/version.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
// Release Information
66
#define MAJOR 1 // Major version number
77
#define MINOR 0 // Minor version number
8-
#define PATCH 0 // Patch release number
8+
#define PATCH 1 // Patch release number
99

1010
#endif // __VERSION_H__

0 commit comments

Comments
 (0)