Skip to content

Commit e49cb00

Browse files
Allen-Webbvitalybuka
authored andcommitted
Unpoison results from LLVMFuzzerMutate.
LLVMFuzzerMutate was returning data marked as uninitialized, but it should be treated at initialized when running with the memory sanitzer.
1 parent 86f0d4a commit e49cb00

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/libfuzzer/libfuzzer_mutator.cc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414

1515
#include "src/libfuzzer/libfuzzer_mutator.h"
1616

17+
#if defined(__has_feature)
18+
# if __has_feature(memory_sanitizer)
19+
#include <sanitizer/msan_interface.h>
20+
# endif
21+
#endif
1722
#include <string.h>
1823

1924
#include <algorithm>
@@ -65,6 +70,12 @@ T MutateValue(T v) {
6570
size_t size =
6671
LLVMFuzzerMutate(reinterpret_cast<uint8_t*>(&v), sizeof(v), sizeof(v));
6772
memset(reinterpret_cast<uint8_t*>(&v) + size, 0, sizeof(v) - size);
73+
// The value from LLVMFuzzerMutate needs to be treated as initialized.
74+
#if defined(__has_feature)
75+
# if __has_feature(memory_sanitizer)
76+
__msan_unpoison(&v, sizeof(v));
77+
# endif
78+
#endif
6879
return v;
6980
}
7081

@@ -93,6 +104,12 @@ std::string Mutator::MutateString(const std::string& value,
93104
result.resize(std::max(1, new_size));
94105
result.resize(LLVMFuzzerMutate(reinterpret_cast<uint8_t*>(&result[0]),
95106
value.size(), result.size()));
107+
// The value from LLVMFuzzerMutate needs to be treated as initialized.
108+
#if defined(__has_feature)
109+
# if __has_feature(memory_sanitizer)
110+
__msan_unpoison(&result[0], result.size());
111+
# endif
112+
#endif
96113
return result;
97114
}
98115

0 commit comments

Comments
 (0)