summaryrefslogtreecommitdiff
path: root/src/basic/string-util.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2017-02-05 20:05:27 -0500
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2017-02-05 21:07:55 -0500
commit2d26d8e07ee680995f96597a1cd713dd81491b89 (patch)
treeca66e286a3319e1edf1d473d7d519c145596ac37 /src/basic/string-util.c
parent52e634271fe96ec23a22705ffb87df59a09d1618 (diff)
treewide: replace homegrown memory_erase with explicit_bzero
explicit_bzero was added in glibc 2.25. Make use of it. explicit_bzero is hardcoded to zero the memory, so string erase now truncates the string, instead of overwriting it with 'x'. This causes a visible difference only in the journalctl case.
Diffstat (limited to 'src/basic/string-util.c')
-rw-r--r--src/basic/string-util.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/basic/string-util.c b/src/basic/string-util.c
index 2ba3604ba0..9d2f4bc8f9 100644
--- a/src/basic/string-util.c
+++ b/src/basic/string-util.c
@@ -821,6 +821,7 @@ int free_and_strdup(char **p, const char *s) {
return 1;
}
+#if !HAVE_DECL_EXPLICIT_BZERO
/*
* Pointer to memset is volatile so that compiler must de-reference
* the pointer and can't assume that it points to any function in
@@ -831,19 +832,19 @@ typedef void *(*memset_t)(void *,int,size_t);
static volatile memset_t memset_func = memset;
-void* memory_erase(void *p, size_t l) {
- return memset_func(p, 'x', l);
+void explicit_bzero(void *p, size_t l) {
+ memset_func(p, '\0', l);
}
+#endif
char* string_erase(char *x) {
-
if (!x)
return NULL;
/* A delicious drop of snake-oil! To be called on memory where
* we stored passphrases or so, after we used them. */
-
- return memory_erase(x, strlen(x));
+ explicit_bzero(x, strlen(x));
+ return x;
}
char *string_free_erase(char *s) {