]> git.ipfire.org Git - thirdparty/knot-dns.git/commitdiff
contrib: use bzero() instead of explicit_bzero() inside memzero() if MSAN detected
authorDaniel Salzman <daniel.salzman@nic.cz>
Sat, 30 Apr 2022 12:26:27 +0000 (14:26 +0200)
committerDaniel Salzman <daniel.salzman@nic.cz>
Sat, 30 Apr 2022 17:42:04 +0000 (19:42 +0200)
MSAN is unable to correctly evaluate explicit_bzero() for memory zeroing in
wire_ctx operations. Then OSS-Fuzz creates false-positive issues. Using bzero()
seems to be a reasonable workaround.

src/contrib/string.c

index 01866860ff580931bb1b2f1304093fa0448f7df9..b4966adafed74b0204eca5e1f6fbf5207c7aa59a 100644 (file)
@@ -148,7 +148,16 @@ void *memzero(void *s, size_t n)
                                        /* In FreeBSD since 11.0. */
                                        /* In glibc since 2.25. */
                                        /* In DragonFly BSD since 5.5. */
+#  if defined(__has_feature)
+#    if __has_feature(memory_sanitizer)
+       #warning "Memory sanitizer detected. Using bzero() instead of explicit_bzero()."
+       bzero(s, n);
+#    else
        explicit_bzero(s, n);
+#    endif
+#  else
+       explicit_bzero(s, n);
+#  endif
        return s;
 #elif defined(HAVE_EXPLICIT_MEMSET)    /* In NetBSD since 7.0. */
        return explicit_memset(s, 0, n);