1 /* OPENBSD ORIGINAL: lib/libc/string/explicit_bzero.c */ 2 /* $OpenBSD: explicit_bzero.c,v 1.1 2014/01/22 21:06:45 tedu Exp $ */ 3 /* 4 * Public domain. 5 * Written by Ted Unangst 6 */ 7 8 #include "includes.h" 9 10 /* 11 * explicit_bzero - don't let the compiler optimize away bzero 12 */ 13 14 #ifndef HAVE_EXPLICIT_BZERO 15 16 #ifdef HAVE_MEMSET_S 17 18 void 19 explicit_bzero(void *p, size_t n) 20 { 21 (void)memset_s(p, n, 0, n); 22 } 23 24 #else /* HAVE_MEMSET_S */ 25 26 /* 27 * Indirect bzero through a volatile pointer to hopefully avoid 28 * dead-store optimisation eliminating the call. 29 */ 30 static void (* volatile ssh_bzero)(void *, size_t) = bzero; 31 32 void 33 explicit_bzero(void *p, size_t n) 34 { 35 ssh_bzero(p, n); 36 } 37 38 #endif /* HAVE_MEMSET_S */ 39 40 #endif /* HAVE_EXPLICIT_BZERO */ 41