]> git.saurik.com Git - apple/security.git/blobdiff - OSX/libsecurity_utilities/lib/alloc.h
Security-59306.61.1.tar.gz
[apple/security.git] / OSX / libsecurity_utilities / lib / alloc.h
index 411b58cb9353d1633f78d5b74888c7dbdd2d6dd8..8d2762278a72a793353ed31b05f367609233c2ad 100644 (file)
@@ -55,10 +55,23 @@ public:
        { return reinterpret_cast<T *>(malloc(sizeof(T))); }
 
        template <class T> T *alloc(UInt32 count) throw(std::bad_alloc)
-       { return reinterpret_cast<T *>(malloc(sizeof(T) * count)); }
+       {
+        size_t bytes = 0;
+        if (__builtin_mul_overflow(sizeof(T), count, &bytes)) {
+            throw std::bad_alloc();
+        }
+        return reinterpret_cast<T *>(malloc(bytes));
+
+    }
 
        template <class T> T *alloc(T *old, UInt32 count) throw(std::bad_alloc)
-       { return reinterpret_cast<T *>(realloc(old, sizeof(T) * count)); }
+       {
+        size_t bytes = 0;
+        if (__builtin_mul_overflow(sizeof(T), count, &bytes)) {
+            throw std::bad_alloc();
+        }
+        return reinterpret_cast<T *>(realloc(old, bytes));
+    }
        
         
        //