]> git.saurik.com Git - apple/dyld.git/blobdiff - src/dyldNew.cpp
dyld-421.2.tar.gz
[apple/dyld.git] / src / dyldNew.cpp
index d68fc4e01479dc6b7667892f84ecaacc304ea200..cf64f58d9f601e48d18d94881d51ff863e2f66f5 100644 (file)
@@ -62,12 +62,16 @@ static dyld_static_pool* currentPool = &initialPool;
 
 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;
@@ -128,7 +132,13 @@ void* calloc(size_t count, size_t 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);
        }
 }