File tree 2 files changed +16
-1
lines changed
2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -103,6 +103,12 @@ if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
103
103
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR} /bin" CACHE PATH "Executable/dll output dir." )
104
104
endif ()
105
105
106
+ include (CheckFunctionExists)
107
+ check_function_exists(memset_s HAVE_MEMSET_S)
108
+ if (HAVE_MEMSET_S)
109
+ add_definitions ("-DHAVE_MEMSET_S=1" )
110
+ endif ()
111
+
106
112
set (JSONCPP_USE_SECURE_MEMORY "0" CACHE STRING "-D...=1 to use memory-wiping allocator for STL" )
107
113
108
114
configure_file ("${PROJECT_SOURCE_DIR} /version.in"
Original file line number Diff line number Diff line change 6
6
#ifndef JSON_ALLOCATOR_H_INCLUDED
7
7
#define JSON_ALLOCATOR_H_INCLUDED
8
8
9
+ #include < algorithm>
9
10
#include < cstring>
10
11
#include < memory>
11
12
@@ -38,8 +39,16 @@ template <typename T> class SecureAllocator {
38
39
* The memory block is filled with zeroes before being released.
39
40
*/
40
41
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)
42
45
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
+
43
52
// free using "global operator delete"
44
53
::operator delete (p);
45
54
}
You can’t perform that action at this time.
0 commit comments