X-Git-Url: https://git.saurik.com/apple/security.git/blobdiff_plain/fa7225c82381bac4432a6edf16f53b5370238d85..7e6b461318c8a779d91381531435a68ee4e8b6ed:/OSX/libsecurity_utilities/lib/alloc.h diff --git a/OSX/libsecurity_utilities/lib/alloc.h b/OSX/libsecurity_utilities/lib/alloc.h index 411b58cb..8d276227 100644 --- a/OSX/libsecurity_utilities/lib/alloc.h +++ b/OSX/libsecurity_utilities/lib/alloc.h @@ -55,10 +55,23 @@ public: { return reinterpret_cast(malloc(sizeof(T))); } template T *alloc(UInt32 count) throw(std::bad_alloc) - { return reinterpret_cast(malloc(sizeof(T) * count)); } + { + size_t bytes = 0; + if (__builtin_mul_overflow(sizeof(T), count, &bytes)) { + throw std::bad_alloc(); + } + return reinterpret_cast(malloc(bytes)); + + } template T *alloc(T *old, UInt32 count) throw(std::bad_alloc) - { return reinterpret_cast(realloc(old, sizeof(T) * count)); } + { + size_t bytes = 0; + if (__builtin_mul_overflow(sizeof(T), count, &bytes)) { + throw std::bad_alloc(); + } + return reinterpret_cast(realloc(old, bytes)); + } //