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
/* 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;
}
return memmem(haystack, haystacklen, needle, needlelen);
}
-#if !HAVE_EXPLICIT_BZERO
-void explicit_bzero(void *p, size_t l);
+#if HAVE_EXPLICIT_BZERO
+static inline void* explicit_bzero_safe(void *p, size_t l) {
+ if (l > 0)
+ explicit_bzero(p, l);
+
+ return p;
+}
+#else
+void explicit_bzero_safe(void *p, size_t l);
#endif
char *string_erase(char *x);
r = send_on_socket(fd, argv[2], packet, length);
finish:
- explicit_bzero(packet, length);
+ explicit_bzero_safe(packet, length);
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}
if (n < m)
break;
- explicit_bzero(p, n);
+ explicit_bzero_safe(p, n);
free(p);
m *= 2;
}
if (!l)
return -ENOMEM;
- explicit_bzero(p, n);
+ explicit_bzero_safe(p, n);
*ret = l;
return 0;
return r;
serial = add_key("user", keyname, p, n, KEY_SPEC_USER_KEYRING);
- explicit_bzero(p, n);
+ explicit_bzero_safe(p, n);
if (serial == -1)
return -errno;
if (!(flags & ASK_PASSWORD_SILENT))
backspace_string(ttyfd, passphrase);
- explicit_bzero(passphrase, sizeof(passphrase));
+ explicit_bzero_safe(passphrase, sizeof(passphrase));
p = codepoint = 0;
} else if (IN_SET(c, '\b', 127)) {
}
p = codepoint = q == (size_t) -1 ? p - 1 : q;
- explicit_bzero(passphrase + p, sizeof(passphrase) - p);
+ explicit_bzero_safe(passphrase + p, sizeof(passphrase) - p);
} else if (!dirty && !(flags & ASK_PASSWORD_SILENT)) {
}
x = strndup(passphrase, p);
- explicit_bzero(passphrase, sizeof(passphrase));
+ explicit_bzero_safe(passphrase, sizeof(passphrase));
if (!x) {
r = -ENOMEM;
goto finish;
l = strv_new("", NULL);
else
l = strv_parse_nulstr(passphrase+1, n-1);
- explicit_bzero(passphrase, n);
+ explicit_bzero_safe(passphrase, n);
if (!l) {
r = -ENOMEM;
goto finish;
r = 0;
finish:
- explicit_bzero(buffer, sizeof(buffer));
+ explicit_bzero_safe(buffer, sizeof(buffer));
return r;
}
r = (int) n;
finish:
- explicit_bzero(packet, packet_length);
+ explicit_bzero_safe(packet, packet_length);
return r;
}