@@ -21,18 +21,18 @@ int tiny_interpose(uint32_t image_index, const char *symbol_name, void *replacem
2121 if (strcmp (segment -> segname , "__DATA_CONST" ) == 0 ) {
2222 if (sym_sects [0 ]) continue ;
2323 struct section_64 * data_const_sect = (void * )(segment + 1 );
24- for (int i = 0 ; i < segment -> nsects ; i ++ ) {
25- if ((data_const_sect [i ].flags & SECTION_TYPE ) == S_NON_LAZY_SYMBOL_POINTERS ) {
26- sym_sects [0 ] = data_const_sect + i ; // __nl_symbol_ptr
24+ for (int j = 0 ; j < segment -> nsects ; j ++ ) {
25+ if ((data_const_sect [j ].flags & SECTION_TYPE ) == S_NON_LAZY_SYMBOL_POINTERS ) {
26+ sym_sects [0 ] = data_const_sect + j ; // __nl_symbol_ptr
2727 }
2828 }
2929 }
3030 else if (strcmp (segment -> segname , "__DATA" ) == 0 ) {
3131 if (sym_sects [1 ]) continue ;
3232 struct section_64 * data_sect = (void * )(segment + 1 );
33- for (int i = 0 ; i < segment -> nsects ; i ++ ) {
34- if ((data_sect [i ].flags & SECTION_TYPE ) == S_LAZY_SYMBOL_POINTERS ) {
35- sym_sects [1 ] = data_sect + i ; // __la_symbol_ptr
33+ for (int j = 0 ; j < segment -> nsects ; j ++ ) {
34+ if ((data_sect [j ].flags & SECTION_TYPE ) == S_LAZY_SYMBOL_POINTERS ) {
35+ sym_sects [1 ] = data_sect + j ; // __la_symbol_ptr
3636 }
3737 }
3838 }
@@ -48,7 +48,11 @@ int tiny_interpose(uint32_t image_index, const char *symbol_name, void *replacem
4848 }
4949 ld_command = (void * )ld_command + ld_command -> cmdsize ;
5050 }
51- intptr_t linkedit_base = image_slide + linkedit_cmd -> vmaddr - linkedit_cmd -> fileoff ;
51+ if (linkedit_cmd == NULL || symtab_cmd == NULL || dysymtab_cmd == NULL ) {
52+ LOG_ERROR ("tiny_interpose: bad mach-o structure!" );
53+ return 1 ;
54+ }
55+ uint64_t linkedit_base = image_slide + linkedit_cmd -> vmaddr - linkedit_cmd -> fileoff ;
5256 char * str_tbl = (void * )linkedit_base + symtab_cmd -> stroff ;
5357 struct nlist_64 * nl_tbl = (void * )linkedit_base + symtab_cmd -> symoff ;
5458 uint32_t * indirect_sym_tbl = (void * )linkedit_base + dysymtab_cmd -> indirectsymoff ;
@@ -60,7 +64,7 @@ int tiny_interpose(uint32_t image_index, const char *symbol_name, void *replacem
6064 if (!sym_sec ) continue ;
6165 void * * sym_ptrs = (void * )sym_sec -> addr + image_slide ;
6266 uint32_t * indirect_sym_entry = indirect_sym_tbl + sym_sec -> reserved1 ; // reserved1 is an index!
63- int nptrs = sym_sec -> size / sizeof (void * );
67+ size_t nptrs = sym_sec -> size / sizeof (void * );
6468 for (int j = 0 ; j < nptrs ; j ++ ) {
6569 uint32_t symtab_index = indirect_sym_entry [j ];
6670 if (symtab_index == INDIRECT_SYMBOL_LOCAL ||
0 commit comments