diff --git a/libr/bin/format/mach0/mach0.c b/libr/bin/format/mach0/mach0.c index 1c498fadb7..cb19130634 100644 --- a/libr/bin/format/mach0/mach0.c +++ b/libr/bin/format/mach0/mach0.c @@ -3994,6 +3994,10 @@ static bool _load_relocations(struct MACH0_(obj_t) *mo) { if (amount < 0) { amount = 0; } + const int bin_limit = mo->limit; + if (bin_limit > 0 && amount > bin_limit) { + amount = bin_limit; + } for (j = 0; j < amount; j++) { struct reloc_t *reloc = R_NEW0 (struct reloc_t); if (!reloc) { diff --git a/libr/bin/p/bin_mach0.c b/libr/bin/p/bin_mach0.c index 2f100da40e..1575f7612c 100644 --- a/libr/bin/p/bin_mach0.c +++ b/libr/bin/p/bin_mach0.c @@ -466,13 +466,24 @@ static RList* patch_relocs(RBinFile *bf) { } r_pvector_push (&ext_relocs, reloc); } - if (mo->reloc_fixups && r_list_length (mo->reloc_fixups) > 0) { + int relocs_count = r_list_length (mo->reloc_fixups); + if (mo->reloc_fixups && relocs_count > 0) { + ut8 buf[8], obuf[8]; RBinReloc *r; RListIter *iter2; + int count = mo->limit; + if (count == 0) { + if (relocs_count > count) { + R_LOG_WARN ("mo.limit for relocs"); + } + count = relocs_count; + } r_list_foreach (mo->reloc_fixups, iter2, r) { + if (count-- < 0) { + break; + } ut64 paddr = r->paddr + mo->baddr; - ut8 buf[8], obuf[8]; r_write_ble64 (buf, r->vaddr, false); b->iob.read_at (b->iob.io, paddr, obuf, 8); if (memcmp (buf, obuf, 8)) {