PWS_STR_MEMNUKE(3) BSD Library Functions Manual PWS_STR_MEMNUKE(3)NAME
pws_str_memnuke — Over-write the contents of a memory buffer with zeros
LIBRARY-lpwstor
SYNOPSIS
#include <pwstor.h>
void
pws_str_memnuke(volatile void *b, size_t sz);
DESCRIPTION
The function pws_str_memnuke() will over-write sz bytes of memory from
the pointer referenced by b with zeros. This is useful for clearing a
memory buffer which contained, for example, a clear-text password. Calls
to free() do not zero the memory, so another application could conceiv‐
ably allocate memory which contains sensitive data from another applica‐
tion. Calling pws_str_memnuke() on the buffer prior to calling free() on
it will prevent this potentially dangerous condition.
CAVEATS
The pws_str_memnuke() function cannot indicate an error, for example if
it returns prematurely because a null-pointer was passed to it. It
requires that b be cast (volatile) in order to prevent compilers from
optimizing it out so that memory is safely wiped.
SEE ALSOpwstor(3)BSD October 23, 2008 BSD