[security] encode quoting chars in HTML and XML
[lighttpd.git] / src / safe_memclear.c
blobada33142633c67f82e832fbc108cb3de349e3f47
1 #include "first.h"
3 #include "settings.h"
5 #include "safe_memclear.h"
7 #include <string.h>
9 #if !defined(HAVE_MEMSET_S) && !defined(HAVE_EXPLICIT_BZERO)
11 # if defined(HAVE_WEAK_SYMBOLS)
12 /* it seems weak functions are never inlined, even for static builds */
13 __attribute__((weak)) void __li_safe_memset_hook(void *buf, size_t len);
15 void __li_safe_memset_hook(void *buf, size_t len)
17 UNUSED(buf);
18 UNUSED(len);
20 # endif /* HAVE_WEAK_SYMBOLS */
22 static void* safe_memset(void *s, int c, size_t n)
24 if (n > 0) {
25 volatile unsigned volatile_zero = 0;
26 volatile unsigned char *vs = (volatile unsigned char*)s;
28 do {
29 memset(s, c, n);
30 } while (vs[volatile_zero] != (unsigned char)c);
31 # if defined(HAVE_WEAK_SYMBOLS)
32 __li_safe_memset_hook(s, n);
33 # endif /* HAVE_WEAK_SYMBOLS */
36 return s;
38 #endif /* !defined(HAVE_MEMSET_S) && !defined(HAVE_EXPLICIT_BZERO) */
41 void safe_memclear(void *s, size_t n) {
42 #if defined(HAVE_MEMSET_S)
43 memset_s(s, n, 0, n);
44 #elif defined(HAVE_EXPLICIT_BZERO)
45 explicit_bzero(s, n);
46 #else
47 safe_memset(s, 0, n);
48 #endif