Skip to content

Commit

Permalink
Use more bin.limit in bin.macho
Browse files Browse the repository at this point in the history
  • Loading branch information
radare authored and trufae committed Sep 18, 2023
1 parent 39d5b0f commit 15cfe29
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 4 additions & 0 deletions libr/bin/format/mach0/mach0.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
15 changes: 13 additions & 2 deletions libr/bin/p/bin_mach0.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down

0 comments on commit 15cfe29

Please sign in to comment.