diff --git a/src/libfuzzer/libfuzzer_mutator.cc b/src/libfuzzer/libfuzzer_mutator.cc index 34d144c..d2502ed 100644 --- a/src/libfuzzer/libfuzzer_mutator.cc +++ b/src/libfuzzer/libfuzzer_mutator.cc @@ -14,6 +14,11 @@ #include "src/libfuzzer/libfuzzer_mutator.h" +#if defined(__has_feature) +# if __has_feature(memory_sanitizer) +#include +# endif +#endif #include #include @@ -65,6 +70,12 @@ T MutateValue(T v) { size_t size = LLVMFuzzerMutate(reinterpret_cast(&v), sizeof(v), sizeof(v)); memset(reinterpret_cast(&v) + size, 0, sizeof(v) - size); + // The value from LLVMFuzzerMutate needs to be treated as initialized. +#if defined(__has_feature) +# if __has_feature(memory_sanitizer) + __msan_unpoison(&v, sizeof(v)); +# endif +#endif return v; } @@ -93,6 +104,12 @@ std::string Mutator::MutateString(const std::string& value, result.resize(std::max(1, new_size)); result.resize(LLVMFuzzerMutate(reinterpret_cast(&result[0]), value.size(), result.size())); + // The value from LLVMFuzzerMutate needs to be treated as initialized. +#if defined(__has_feature) +# if __has_feature(memory_sanitizer) + __msan_unpoison(&result[0], result.size()); +# endif +#endif return result; }