string-util: introduce explicit_zero_safe()
The only real difference is that this wrapper can deal with NULL pointer arguments, but only if the length is also zero. CID 1396277
This commit is contained in:
@@ -1059,8 +1059,11 @@ typedef void *(*memset_t)(void *,int,size_t);
|
||||
|
||||
static volatile memset_t memset_func = memset;
|
||||
|
||||
void explicit_bzero(void *p, size_t l) {
|
||||
memset_func(p, '\0', l);
|
||||
void* explicit_bzero_safe(void *p, size_t l) {
|
||||
if (l > 0)
|
||||
memset_func(p, '\0', l);
|
||||
|
||||
return p;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1070,7 +1073,7 @@ char* string_erase(char *x) {
|
||||
|
||||
/* A delicious drop of snake-oil! To be called on memory where
|
||||
* we stored passphrases or so, after we used them. */
|
||||
explicit_bzero(x, strlen(x));
|
||||
explicit_bzero_safe(x, strlen(x));
|
||||
return x;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user