From cc301348df0acff69827f9ee23b817521a129300 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Moreau?= Date: Fri, 1 Nov 2013 18:32:36 -0400 Subject: [PATCH] libwinpr-crt: added SecureZeroMemory --- winpr/include/winpr/memory.h | 4 +++- winpr/libwinpr/crt/memory.c | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/winpr/include/winpr/memory.h b/winpr/include/winpr/memory.h index c8fbafd68..3a99685a8 100644 --- a/winpr/include/winpr/memory.h +++ b/winpr/include/winpr/memory.h @@ -30,9 +30,11 @@ #define CopyMemory(Destination, Source, Length) memcpy((Destination), (Source), (Length)) #define MoveMemory(Destination, Source, Length) memmove((Destination), (Source), (Length)) -#define FillMemory(Destination, Length, Fill) memset((Destination), (Fill), (Length)) +#define FillMemory(Destination, Length, Fill) memset((Destination), (Fill), (Length)) #define ZeroMemory(Destination, Length) memset((Destination), 0, (Length)) +WINPR_API PVOID SecureZeroMemory(PVOID ptr, SIZE_T cnt); + #endif #include diff --git a/winpr/libwinpr/crt/memory.c b/winpr/libwinpr/crt/memory.c index 39ac0dbe3..d83cf8493 100644 --- a/winpr/libwinpr/crt/memory.c +++ b/winpr/libwinpr/crt/memory.c @@ -28,6 +28,17 @@ #ifndef _WIN32 +PVOID SecureZeroMemory(PVOID ptr, SIZE_T cnt) +{ + volatile BYTE* p = ptr; + while (cnt--) + { + *p = 0; + p++; + } + + return ptr; +} #endif