diff --git a/Elf2Mac/Section.cc b/Elf2Mac/Section.cc index bda3e75420..10bb06c807 100644 --- a/Elf2Mac/Section.cc +++ b/Elf2Mac/Section.cc @@ -62,10 +62,10 @@ void Section::SetRela(Elf_Scn *scn) GElf_Rela 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 - // in LD output. That's bad. Let's ignore it. + // FIXME: There are sometimes relocations beyond the end of the sections + // in LD output for some reason. That's bad. Let's ignore it. continue; } relocs.push_back(rela); diff --git a/libretro/MultiSegApp.c b/libretro/MultiSegApp.c index d0bb5f6a21..cb5f92abfb 100644 --- a/libretro/MultiSegApp.c +++ b/libretro/MultiSegApp.c @@ -94,7 +94,7 @@ pascal void* Retro68LoadSegment(uint8_t *p) Handle RELA = NULL; RELA = GetResource('RELA', id); assert(RELA); - Retro68ApplyRelocations(base + 40, codeSize, *RELA, displacements); + Retro68ApplyRelocations(base + 40, codeSize - 40, *RELA, displacements); HPurge(RELA); } diff --git a/libretro/relocate.c b/libretro/relocate.c index 2d132a653f..c2b6dc0689 100644 --- a/libretro/relocate.c +++ b/libretro/relocate.c @@ -131,7 +131,7 @@ void Retro68ApplyRelocations(uint8_t *base, uint32_t size, void *relocations, ui uint8_t kind = val & 0x3; assert(addrPtr >= base); - assert(addrPtr < base + size); + assert(addrPtr <= base + size - 4); uint8_t *addr = (uint8_t*) READ_UNALIGNED_LONGWORD(addrPtr); addr += displacements[kind];