Skip to content

Commit d1da513

Browse files
committed
fixed tiny_interpose crashing issue
1 parent db1dbb9 commit d1da513

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/interpose.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ int tiny_interpose(uint32_t image_index, const char *symbol_name, void *replacem
6161
void **sym_ptrs = (void *)sym_sec->addr + image_slide;
6262
uint32_t *indirect_sym_entry = indirect_sym_tbl + sym_sec->reserved1; // reserved1 is an index!
6363
int nptrs = sym_sec->size / sizeof(void *);
64-
for (int i = 0; i < nptrs; i++) {
65-
uint32_t symtab_index = indirect_sym_entry[i];
64+
for (int j = 0; j < nptrs; j++) {
65+
uint32_t symtab_index = indirect_sym_entry[j];
6666
if (symtab_index == INDIRECT_SYMBOL_LOCAL ||
6767
symtab_index == (INDIRECT_SYMBOL_LOCAL | INDIRECT_SYMBOL_ABS)) {
6868
continue;
@@ -74,7 +74,7 @@ int tiny_interpose(uint32_t image_index, const char *symbol_name, void *replacem
7474
VM_PROT_READ | VM_PROT_WRITE | VM_PROT_COPY);
7575
if (err != 0) goto exit;
7676
}
77-
sym_ptrs[i] = replacement;
77+
sym_ptrs[j] = replacement;
7878
goto exit;
7979
}
8080
}

src/private.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44
#include <TargetConditionals.h>
55

66
#include <mach/mach_init.h> // mach_task_self()
7-
#if TARGET_OS_IPHONE
7+
#if TARGET_OS_OSX
8+
#include <mach/mach_vm.h> // mach_vm_*
9+
#elif TARGET_OS_IOS
810
#include <mach/vm_map.h> // vm_*
911
#define mach_vm_address_t vm_address_t
1012
#define mach_vm_allocate vm_allocate
1113
#define mach_vm_deallocate vm_deallocate
1214
#define mach_vm_read vm_read
1315
#define mach_vm_write vm_write
1416
#define mach_vm_protect vm_protect
15-
#elif TARGET_OS_MAC
16-
#include <mach/mach_vm.h> // mach_vm_*
1717
#endif
1818

1919
#ifdef COMPACT

0 commit comments

Comments
 (0)