File tree Expand file tree Collapse file tree 2 files changed +16
-1
lines changed
Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -93,6 +93,12 @@ if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
9393 set (CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR} /bin" CACHE PATH "Executable/dll output dir." )
9494endif ()
9595
96+ include (CheckFunctionExists )
97+ check_function_exists (memset_s HAVE_MEMSET_S )
98+ if (HAVE_MEMSET_S)
99+ add_definitions ("-DHAVE_MEMSET_S=1" )
100+ endif ()
101+
96102if (JSONCPP_USE_SECURE_MEMORY)
97103 add_definitions ("-DJSONCPP_USE_SECURE_MEMORY=1" )
98104endif ()
Original file line number Diff line number Diff line change 66#ifndef JSON_ALLOCATOR_H_INCLUDED
77#define JSON_ALLOCATOR_H_INCLUDED
88
9+ #include < algorithm>
910#include < cstring>
1011#include < memory>
1112
@@ -38,8 +39,16 @@ template <typename T> class SecureAllocator {
3839 * The memory block is filled with zeroes before being released.
3940 */
4041 void deallocate (pointer p, size_type n) {
41- // memset_s is used because memset may be optimized away by the compiler
42+ // These constructs will not be removed by the compiler during optimization,
43+ // unlike memset.
44+ #if defined(HAVE_MEMSET_S)
4245 memset_s (p, n * sizeof (T), 0 , n * sizeof (T));
46+ #elif defined(_WIN32)
47+ RtlSecureZeroMemory (p, n * sizeof (T));
48+ #else
49+ std::fill_n (reinterpret_cast <volatile unsigned char *>(p), n, 0 );
50+ #endif
51+
4352 // free using "global operator delete"
4453 ::operator delete (p);
4554 }
You can’t perform that action at this time.
0 commit comments