utils: Handle NULL consistently if memwipe() is implemented via explicit_bzero()
Our own implementation ignores NULL values, however, explicit_bzero()
can't handle that, as indicated by the `__nonnull ((1))` attribute in the
function's signature in string.h, and causes a segmentation fault. This
was noticed in one of the unit tests for NewHope. Since we usually use
memwipe() via chunk_clear(), which already ignores NULL pointers, this
is not that much of an issue in practice.
Fixes: 149d1bbb05 ("memory: Use explicit_bzero() as memwipe() if available")
This commit is contained in:
@@ -87,7 +87,13 @@ static inline void *memset_noop(void *s, int c, size_t n)
|
||||
void memxor(uint8_t dest[], const uint8_t src[], size_t n);
|
||||
|
||||
#ifdef HAVE_EXPLICIT_BZERO
|
||||
#define memwipe(ptr, n) explicit_bzero(ptr, n)
|
||||
static inline void memwipe(void *ptr, size_t n)
|
||||
{
|
||||
if (ptr)
|
||||
{
|
||||
explicit_bzero(ptr, n);
|
||||
}
|
||||
}
|
||||
#else /* HAVE_EXPLICIT_BZERO */
|
||||
/**
|
||||
* Safely overwrite n bytes of memory at ptr with zero, non-inlining variant.
|
||||
|
||||
Reference in New Issue
Block a user