void* malloc(size_t size)
{
- if ( dyld::gLibSystemHelpers != NULL) {
+ if ( (dyld::gLibSystemHelpers != NULL) && dyld::gProcessInfo->libSystemInitialized ) {
void* p = dyld::gLibSystemHelpers->malloc(size);
//dyld::log("malloc(%lu) => %p from libSystem\n", size, p);
return p;
}
else {
+ if ( size > DYLD_POOL_CHUNK_SIZE ) {
+ dyld::log("dyld malloc overflow: size=%zu\n", size);
+ exit(1);
+ }
size = (size+sizeof(void*)-1) & (-sizeof(void*)); // pointer align
uint8_t* result = currentPool->current;
currentPool->current += size;
return result;
}
else {
- return malloc(count*size);
+ // Check for overflow of integer multiplication
+ size_t total = count * size;
+ if ( total/count != size ) {
+ dyld::log("dyld calloc overflow: count=%zu, size=%zu\n", count, size);
+ exit(1);
+ }
+ return malloc(total);
}
}