diff options
author | Damien Miller <djm@mindrot.org> | 2014-08-27 06:32:01 +1000 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2014-08-27 06:32:01 +1000 |
commit | 3d673d103bad35afaec6e7ef73e5277216ce33a3 (patch) | |
tree | 646afea264f1f91573e590f1ae5818cfb7f7b296 /openbsd-compat | |
parent | 146218ac11a1eb0dcade6f793d7acdef163b5ddc (diff) |
- (djm) [openbsd-compat/explicit_bzero.c] implement explicit_bzero()
using memset_s() where possible; improve fallback to indirect bzero
via a volatile pointer to give it more of a chance to avoid being
optimised away.
Diffstat (limited to 'openbsd-compat')
-rw-r--r-- | openbsd-compat/explicit_bzero.c | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/openbsd-compat/explicit_bzero.c b/openbsd-compat/explicit_bzero.c index b106741e..3c85a484 100644 --- a/openbsd-compat/explicit_bzero.c +++ b/openbsd-compat/explicit_bzero.c @@ -7,14 +7,34 @@ #include "includes.h" +/* + * explicit_bzero - don't let the compiler optimize away bzero + */ + #ifndef HAVE_EXPLICIT_BZERO +#ifdef HAVE_MEMSET_S + +void +explicit_bzero(void *p, size_t n) +{ + (void)memset_s(p, n, 0, n); +} + +#else /* HAVE_MEMSET_S */ + /* - * explicit_bzero - don't let the compiler optimize away bzero + * Indirect bzero through a volatile pointer to hopefully avoid + * dead-store optimisation eliminating the call. */ +static void (* volatile ssh_bzero)(void *, size_t) = bzero; + void explicit_bzero(void *p, size_t n) { - bzero(p, n); + ssh_bzero(p, n); } -#endif + +#endif /* HAVE_MEMSET_S */ + +#endif /* HAVE_EXPLICIT_BZERO */ |