summaryrefslogtreecommitdiff
path: root/openbsd-compat
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2016-08-16 13:28:23 +1000
committerDamien Miller <djm@mindrot.org>2016-08-16 13:37:26 +1000
commit74433a19bb6f4cef607680fa4d1d7d81ca3826aa (patch)
tree3eabfcfe2a1ab1bd90479e390c5b61545652ef7d /openbsd-compat
parent6cb6dcffe1a2204ba9006de20f73255c268fcb6b (diff)
fix false positives when compiled with msan
Our explicit_bzero successfully confused clang -fsanitize-memory in to thinking that memset is never called to initialise memory. Ensure that it is called in a way that the compiler recognises.
Diffstat (limited to 'openbsd-compat')
-rw-r--r--openbsd-compat/explicit_bzero.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/openbsd-compat/explicit_bzero.c b/openbsd-compat/explicit_bzero.c
index 3c85a4843..5078134d1 100644
--- a/openbsd-compat/explicit_bzero.c
+++ b/openbsd-compat/explicit_bzero.c
@@ -7,6 +7,8 @@
7 7
8#include "includes.h" 8#include "includes.h"
9 9
10#include <string.h>
11
10/* 12/*
11 * explicit_bzero - don't let the compiler optimize away bzero 13 * explicit_bzero - don't let the compiler optimize away bzero
12 */ 14 */
@@ -32,6 +34,17 @@ static void (* volatile ssh_bzero)(void *, size_t) = bzero;
32void 34void
33explicit_bzero(void *p, size_t n) 35explicit_bzero(void *p, size_t n)
34{ 36{
37 /*
38 * clang -fsanitize=memory needs to intercept memset-like functions
39 * to correctly detect memory initialisation. Make sure one is called
40 * directly since our indirection trick above sucessfully confuses it.
41 */
42#if defined(__has_feature)
43# if __has_feature(memory_sanitizer)
44 memset(p, 0, n);
45# endif
46#endif
47
35 ssh_bzero(p, n); 48 ssh_bzero(p, n);
36} 49}
37 50