X-Git-Url: https://git.saurik.com/apple/security.git/blobdiff_plain/5c19dc3ae3bd8e40a9c028b0deddd50ff337692c..2973440143693ed88ec4a84745ea02f47376daa1:/OSX/libsecurity_utilities/lib/alloc.cpp diff --git a/OSX/libsecurity_utilities/lib/alloc.cpp b/OSX/libsecurity_utilities/lib/alloc.cpp index 61992434..313d187e 100644 --- a/OSX/libsecurity_utilities/lib/alloc.cpp +++ b/OSX/libsecurity_utilities/lib/alloc.cpp @@ -27,13 +27,16 @@ // // Don't eat heavily before inspecting this code. // +#define __STDC_WANT_LIB_EXT1__ 1 +#include + #include #include #include #include #include -using LowLevelMemoryUtilities::alignof; +using LowLevelMemoryUtilities::alignof_template; using LowLevelMemoryUtilities::increment; using LowLevelMemoryUtilities::alignUp; @@ -111,7 +114,8 @@ void *DefaultAllocator::realloc(void *addr, size_t newSize) throw(std::bad_alloc void SensitiveAllocator::free(void *addr) throw() { - memset(addr, 0, malloc_size(addr)); + size_t size = malloc_size(addr); + ::memset_s(addr, size, 0, size); DefaultAllocator::free(addr); } @@ -119,7 +123,7 @@ void *SensitiveAllocator::realloc(void *addr, size_t newSize) throw(std::bad_all { size_t oldSize = malloc_size(addr); if (newSize < oldSize) - memset(increment(addr, newSize), 0, oldSize - newSize); + ::memset_s(increment(addr, newSize), oldSize - newSize, 0, oldSize - newSize); return DefaultAllocator::realloc(addr, newSize); } @@ -135,7 +139,7 @@ void *CssmHeap::operator new (size_t size, Allocator *alloc) throw(std::bad_allo { if (alloc == NULL) alloc = &Allocator::standard(); - size = alignUp(size, alignof()); + size = alignUp(size, alignof_template()); size_t totalSize = size + sizeof(Allocator *); void *addr = alloc->malloc(totalSize); *(Allocator **)increment(addr, size) = alloc; @@ -149,7 +153,7 @@ void CssmHeap::operator delete (void *addr, size_t size, Allocator *alloc) throw void CssmHeap::operator delete (void *addr, size_t size) throw() { - void *end = increment(addr, alignUp(size, alignof())); + void *end = increment(addr, alignUp(size, alignof_template())); (*(Allocator **)end)->free(addr); }