[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 2/5] Use SecureZeroMemory on windows for explicit_bzero
From: |
roucaries . bastien |
Subject: |
[PATCH 2/5] Use SecureZeroMemory on windows for explicit_bzero |
Date: |
Sat, 11 Apr 2020 23:20:32 +0200 |
From: Bastien Roucariès <address@hidden>
Signed-off-by: Bastien Roucariès <address@hidden>
---
lib/explicit_bzero.c | 7 +++++++
m4/explicit_bzero.m4 | 5 +++++
2 files changed, 12 insertions(+)
diff --git a/lib/explicit_bzero.c b/lib/explicit_bzero.c
index 862855421..b355f9bdf 100644
--- a/lib/explicit_bzero.c
+++ b/lib/explicit_bzero.c
@@ -32,6 +32,11 @@
#include <string.h>
+#if defined WIN32 && defined HAVE_SECUREZEROMEMORY
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#endif
+
#if _LIBC
/* glibc-internal users use __explicit_bzero_chk, and explicit_bzero
redirects to that. */
@@ -47,6 +52,8 @@ explicit_bzero (void *s, size_t len)
explicit_memset (s, 0, len);
#elif HAVE_MEMSET_S
(void) memset_s(s,len,'\0',len);
+#elif HAVE_SECUREZEROMEMORY
+ (void) SecureZeroMemory(s,len);
#else
memset (s, '\0', len);
# if defined __GNUC__ && !defined __clang__
diff --git a/m4/explicit_bzero.m4 b/m4/explicit_bzero.m4
index 3ca5dc771..8f3144342 100644
--- a/m4/explicit_bzero.m4
+++ b/m4/explicit_bzero.m4
@@ -19,6 +19,11 @@ AC_DEFUN([gl_FUNC_EXPLICIT_BZERO],
if test $ac_cv_func_memset_s = no; then
HAVE_MEMSET_S=0
fi
+
+ AC_CHECK_FUNCS_ONCE([SecureZeroMemory])
+ if test $ac_cv_func_SecureZeroMemory = no; then
+ HAVE_SECUREZEROMEMORY=0
+ fi
])
AC_DEFUN([gl_PREREQ_EXPLICIT_BZERO],
--
2.25.1
- [patch] Improve explicit_bzero, roucaries . bastien, 2020/04/11
- [PATCH 1/5] Use memset_s if possible for explicit_bzero, roucaries . bastien, 2020/04/11
- [PATCH 2/5] Use SecureZeroMemory on windows for explicit_bzero,
roucaries . bastien <=
- [PATCH 5/5] Fix styling in explicit bzero, roucaries . bastien, 2020/04/11
- [PATCH 3/5] Support clang for explicit_bzero, roucaries . bastien, 2020/04/11
- [PATCH 4/5] Use volatile trick for explicit_bzero, roucaries . bastien, 2020/04/11
- Re: [patch] Improve explicit_bzero, Bruno Haible, 2020/04/11