Core: Fix loading ELF files that have unexpected empty program headers

This commit is contained in:
Vicki Pfau 2020-11-24 01:37:54 -08:00
parent 6ca62fae83
commit f7749b31de
2 changed files with 4 additions and 0 deletions

View File

@ -56,6 +56,7 @@ Other fixes:
- CMake: Link with correct OpenGL library (fixes mgba.io/i/1872) - CMake: Link with correct OpenGL library (fixes mgba.io/i/1872)
- Core: Ensure ELF regions can be written before trying - Core: Ensure ELF regions can be written before trying
- Core: Fix threading improperly setting paused state while interrupted - Core: Fix threading improperly setting paused state while interrupted
- Core: Fix loading ELF files that have unexpected empty program headers
- Debugger: Don't skip undefined instructions when debugger attached - Debugger: Don't skip undefined instructions when debugger attached
- Debugger: Close trace log when done tracing - Debugger: Close trace log when done tracing
- Debugger: Fix change watchpoints (fixes mgba.io/i/1947) - Debugger: Fix change watchpoints (fixes mgba.io/i/1947)

View File

@ -382,6 +382,9 @@ bool mCoreLoadELF(struct mCore* core, struct ELF* elf) {
for (i = 0; i < ELFProgramHeadersSize(&ph); ++i) { for (i = 0; i < ELFProgramHeadersSize(&ph); ++i) {
size_t bsize, esize; size_t bsize, esize;
Elf32_Phdr* phdr = ELFProgramHeadersGetPointer(&ph, i); Elf32_Phdr* phdr = ELFProgramHeadersGetPointer(&ph, i);
if (!phdr->p_filesz) {
continue;
}
void* block = mCoreGetMemoryBlockMasked(core, phdr->p_paddr, &bsize, mCORE_MEMORY_WRITE | mCORE_MEMORY_WORM); void* block = mCoreGetMemoryBlockMasked(core, phdr->p_paddr, &bsize, mCORE_MEMORY_WRITE | mCORE_MEMORY_WORM);
char* bytes = ELFBytes(elf, &esize); char* bytes = ELFBytes(elf, &esize);
if (block && bsize >= phdr->p_filesz && esize > phdr->p_offset && esize >= phdr->p_filesz + phdr->p_offset) { if (block && bsize >= phdr->p_filesz && esize > phdr->p_offset && esize >= phdr->p_filesz + phdr->p_offset) {