]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fuzz-unit-file: add __has_feature(memory_sanitizer) when skipping ListenNetlink=
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sun, 25 Mar 2018 20:26:13 +0000 (22:26 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 26 Mar 2018 13:28:03 +0000 (15:28 +0200)
https://clang.llvm.org/docs/MemorySanitizer.html#id5 documents this
check as the way to detect MemorySanitizer at compilation time. We
only need to skip the test if MemorySanitizer is used.

Also, use this condition in cg_slice_to_path(). There, the code that is
conditionalized is not harmful in any way (it's just unnecessary), so remove
the FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION condition.

Fixes #8482.

src/basic/cgroup-util.c
src/basic/macro.h
src/fuzz/fuzz-unit-file.c

index 5934ee6e8a4f54421666af68e4c2212fd5300581..67e690d6f5a2621997423a36c071cf774234ea94 100644 (file)
@@ -1976,7 +1976,7 @@ int cg_slice_to_path(const char *unit, char **ret) {
                 _cleanup_free_ char *escaped = NULL;
                 char n[dash - p + sizeof(".slice")];
 
-#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
+#if HAS_FEATURE_MEMORY_SANITIZER
                 /* msan doesn't instrument stpncpy, so it thinks
                  * n is later used unitialized:
                  * https://github.com/google/sanitizers/issues/926
index 8911edfc4be6bf37bd59eb5f8d4fece7a032db7e..8e61ff068505406ee2b88cf2e2b095ea512e106b 100644 (file)
 #endif
 #endif
 
+#if !defined(HAS_FEATURE_MEMORY_SANITIZER)
+#  if defined(__has_feature)
+#    if __has_feature(memory_sanitizer)
+#      define HAS_FEATURE_MEMORY_SANITIZER 1
+#    endif
+#  endif
+#  if !defined(HAS_FEATURE_MEMORY_SANITIZER)
+#    define HAS_FEATURE_MEMORY_SANITIZER 0
+#  endif
+#endif
+
 /* Temporarily disable some warnings */
 #define DISABLE_WARNING_DECLARATION_AFTER_STATEMENT                     \
         _Pragma("GCC diagnostic push");                                 \
index a5cd9b4aa9cd20837c8ff6ddc1809cb1a5b47262..17da776ae335204b3b7acf1c7b4bbc2cbf0db5b1 100644 (file)
@@ -48,7 +48,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
 
                 ll = l + strspn(l, WHITESPACE);
 
-                if (startswith(ll, "ListenNetlink=")) {
+                if (HAS_FEATURE_MEMORY_SANITIZER && startswith(ll, "ListenNetlink=")) {
                         /* ListenNetlink causes a false positive in msan,
                          * let's skip this for now. */
                         log_notice("Skipping test because ListenNetlink= is present");