diff options
author | Jussi Kivilinna <[email protected]> | 2018-12-01 11:43:09 +0000 |
---|---|---|
committer | Jussi Kivilinna <[email protected]> | 2018-12-01 11:43:09 +0000 |
commit | 2a650772b4e1c78a4fd20bc88433930e5551fe9c (patch) | |
tree | 1ec63e3e9e09cba7dcaf080517379625769b98e0 /common/mischelp.c | |
parent | scd: Add strerror to new error message. (diff) | |
download | gnupg-2a650772b4e1c78a4fd20bc88433930e5551fe9c.tar.gz gnupg-2a650772b4e1c78a4fd20bc88433930e5551fe9c.zip |
common/mischelp: use platform memory zeroing function for wipememory
* common/mischelp.h (wipememory): Replace macro with function
prototype.
(wipememory2): Remove.
* common/mischelp.c (wipememory): New.
* configure.ac (AC_CHECK_FUNCS): Check for 'explicit_bzero'.
--
In new wipememory function, memory is cleared through platform
provided secure memory zeroing function, SecureZeroMemory
or explicit_bzero.
If none of these is available, memset is called through
volatile function pointer to so that compiler won't optimize
away the call.
Signed-off-by: Jussi Kivilinna <[email protected]>
Diffstat (limited to 'common/mischelp.c')
-rw-r--r-- | common/mischelp.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/common/mischelp.c b/common/mischelp.c index 75ba60714..81dd501f8 100644 --- a/common/mischelp.c +++ b/common/mischelp.c @@ -49,6 +49,22 @@ #include "mischelp.h" +void +wipememory (void *ptr, size_t len) +{ +#if defined(HAVE_W32_SYSTEM) && defined(SecureZeroMemory) + SecureZeroMemory (ptr, len); +#elif defined(HAVE_EXPLICIT_BZERO) + explicit_bzero (ptr, len); +#else + /* Prevent compiler from optimizing away the call to memset by accessing + memset through volatile pointer. */ + static void *(*volatile memset_ptr)(void *, int, size_t) = (void *)memset; + memset_ptr (ptr, 0, len); +#endif +} + + /* Check whether the files NAME1 and NAME2 are identical. This is for example achieved by comparing the inode numbers of the files. */ int |