[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 2/2] misc: explicit_bzero: Use SecureZeroMemory if available


Useful on Windows platforms where SecureZeroMemory is available.

Signed-off-by: Alberto Aguirre <albaguirre@xxxxxxxxx>
---
 ConfigureChecks.cmake | 2 ++
 config.h.cmake        | 3 +++
 src/misc.c            | 2 ++
 3 files changed, 7 insertions(+)

diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake
index f495faf0..fc42d982 100644
--- a/ConfigureChecks.cmake
+++ b/ConfigureChecks.cmake
@@ -180,6 +180,8 @@ if (WIN32)
     check_function_exists(_strtoui64 HAVE__STRTOUI64)
 
     set(HAVE_SELECT TRUE)
+
+    check_symbol_exists(SecureZeroMemory "windows.h" HAVE_SECURE_ZERO_MEMORY)
 else (WIN32)
     check_function_exists(poll HAVE_POLL)
     check_function_exists(select HAVE_SELECT)
diff --git a/config.h.cmake b/config.h.cmake
index dea776ed..3a14b450 100644
--- a/config.h.cmake
+++ b/config.h.cmake
@@ -166,6 +166,9 @@
 /* Define to 1 if you have the `memset_s' function. */
 #cmakedefine HAVE_MEMSET_S 1
 
+/* Define to 1 if you have the `SecureZeroMemory' function. */
+#cmakedefine HAVE_SECURE_ZERO_MEMORY 1
+
 /*************************** LIBRARIES ***************************/
 
 /* Define to 1 if you have the `crypto' library (-lcrypto). */
diff --git a/src/misc.c b/src/misc.c
index c7b34f26..9f424281 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -1057,6 +1057,8 @@ void explicit_bzero(void *s, size_t n)
 {
 #if defined(HAVE_MEMSET_S)
     memset_s(s, n, '\0', n);
+#elif defined(HAVE_SECURE_ZERO_MEMORY)
+    SecureZeroMemory(s, n);
 #else
     memset(s, '\0', n);
 #if defined(HAVE_GCC_VOLATILE_MEMORY_PROTECTION)
-- 
2.14.1


References:
[PATCH 0/2] Prefer memset_s or SecureZeroMemory if availableAlberto Aguirre <albaguirre@xxxxxxxxx>
Archive administrator: postmaster@lists.cynapses.org