]> git.saurik.com Git - apple/security.git/blobdiff - OSX/libsecurity_utilities/lib/alloc.cpp
Security-58286.60.28.tar.gz
[apple/security.git] / OSX / libsecurity_utilities / lib / alloc.cpp
index 61992434e5973735d97f25741d66f4a0f408d41d..313d187ec96eb37c703a18a12aa5f248574de2e4 100644 (file)
 //
 // Don't eat heavily before inspecting this code.
 //
+#define __STDC_WANT_LIB_EXT1__ 1
+#include <string.h>
+
 #include <security_utilities/alloc.h>
 #include <security_utilities/memutils.h>
 #include <security_utilities/globalizer.h>
 #include <stdlib.h>
 #include <errno.h>
 
-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<Allocator *>());
+       size = alignUp(size, alignof_template<Allocator *>());
        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<Allocator *>()));
+       void *end = increment(addr, alignUp(size, alignof_template<Allocator *>()));
        (*(Allocator **)end)->free(addr);
 }