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 #include <string.h>
10 
11 /*
12  * explicit_bzero - don't let the compiler optimize away bzero
13  */
14 
15 #ifndef HAVE_EXPLICIT_BZERO
16 
17 #ifdef HAVE_MEMSET_S
18 
19 void
explicit_bzero(void * p,size_t n)20 explicit_bzero(void *p, size_t n)
21 {
22 	(void)memset_s(p, n, 0, n);
23 }
24 
25 #else /* HAVE_MEMSET_S */
26 
27 /*
28  * Indirect bzero through a volatile pointer to hopefully avoid
29  * dead-store optimisation eliminating the call.
30  */
31 static void* (* volatile ssh_memset)(void *, int, size_t) = memset;
32 
33 void
explicit_bzero(void * p,size_t n)34 explicit_bzero(void *p, size_t n)
35 {
36 	ssh_memset(p, 0, n);
37 }
38 
39 #endif /* HAVE_MEMSET_S */
40 
41 #endif /* HAVE_EXPLICIT_BZERO */
42