Fix crashes caused by 68K relocations past the end of sections; still no idea what's going on.

This commit is contained in:
Wolfgang Thaller 2019-01-08 22:58:30 +01:00
parent 380fef0114
commit bbc3a1f049
3 changed files with 5 additions and 5 deletions

View File

@ -62,10 +62,10 @@ void Section::SetRela(Elf_Scn *scn)
GElf_Rela rela; GElf_Rela rela;
gelf_getrela(data, i, &rela); gelf_getrela(data, i, &rela);
if(rela.r_offset < shdr.sh_addr || rela.r_offset >= shdr.sh_addr + shdr.sh_size) if(rela.r_offset < shdr.sh_addr || rela.r_offset > shdr.sh_addr + shdr.sh_size - 4)
{ {
// For some reason, there sometimes are relocations beyond the end of the sections // FIXME: There are sometimes relocations beyond the end of the sections
// in LD output. That's bad. Let's ignore it. // in LD output for some reason. That's bad. Let's ignore it.
continue; continue;
} }
relocs.push_back(rela); relocs.push_back(rela);

View File

@ -94,7 +94,7 @@ pascal void* Retro68LoadSegment(uint8_t *p)
Handle RELA = NULL; Handle RELA = NULL;
RELA = GetResource('RELA', id); RELA = GetResource('RELA', id);
assert(RELA); assert(RELA);
Retro68ApplyRelocations(base + 40, codeSize, *RELA, displacements); Retro68ApplyRelocations(base + 40, codeSize - 40, *RELA, displacements);
HPurge(RELA); HPurge(RELA);
} }

View File

@ -131,7 +131,7 @@ void Retro68ApplyRelocations(uint8_t *base, uint32_t size, void *relocations, ui
uint8_t kind = val & 0x3; uint8_t kind = val & 0x3;
assert(addrPtr >= base); assert(addrPtr >= base);
assert(addrPtr < base + size); assert(addrPtr <= base + size - 4);
uint8_t *addr = (uint8_t*) READ_UNALIGNED_LONGWORD(addrPtr); uint8_t *addr = (uint8_t*) READ_UNALIGNED_LONGWORD(addrPtr);
addr += displacements[kind]; addr += displacements[kind];