]> git.saurik.com Git - apple/security.git/blobdiff - OSX/libsecurity_utilities/lib/alloc.cpp
Security-59306.120.7.tar.gz
[apple/security.git] / OSX / libsecurity_utilities / lib / alloc.cpp
index 313d187ec96eb37c703a18a12aa5f248574de2e4..5d297087347a30401c16306fd96da364a11d3593 100644 (file)
@@ -137,8 +137,12 @@ void *SensitiveAllocator::realloc(void *addr, size_t newSize) throw(std::bad_all
 //
 void *CssmHeap::operator new (size_t size, Allocator *alloc) throw(std::bad_alloc)
 {
 //
 void *CssmHeap::operator new (size_t size, Allocator *alloc) throw(std::bad_alloc)
 {
-       if (alloc == NULL)
+    if (size > SIZE_T_MAX / 2) {
+        throw std::bad_alloc();
+    }
+    if (alloc == NULL) {
                alloc = &Allocator::standard();
                alloc = &Allocator::standard();
+    }
        size = alignUp(size, alignof_template<Allocator *>());
        size_t totalSize = size + sizeof(Allocator *);
        void *addr = alloc->malloc(totalSize);
        size = alignUp(size, alignof_template<Allocator *>());
        size_t totalSize = size + sizeof(Allocator *);
        void *addr = alloc->malloc(totalSize);