1// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
2// See https://llvm.org/LICENSE.txt for license information.
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
5// Triggers the bug described here:
6// https://github.com/google/oss-fuzz/issues/4605
7//
8// Tests that custom mutators do not cause MSan false positives. We are careful
9// to use every parameter to ensure none cause false positives.
10
11#include <algorithm>
12#include <cstddef>
13#include <cstdint>
14#include <cstdio>
15#include <cstring>
16
17extern "C" {
18
19int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { return 0; }
20
21size_t LLVMFuzzerCustomMutator(uint8_t *Data, size_t Size, size_t MaxSize,
22 unsigned int Seed) {
23 if (Seed == 7)
24 return 0;
25 if (MaxSize == 0)
26 return 0;
27 for (size_t I = 0; I < Size; ++I) {
28 if (Data[I] == 42) {
29 printf("BINGO\n");
30 }
31 }
32 return Size;
33}
34
35size_t LLVMFuzzerCustomCrossOver(
36 const uint8_t *Data1, size_t Size1, const uint8_t *Data2, size_t Size2,
37 uint8_t *Out, size_t MaxOutSize, unsigned int Seed) {
38 if (Seed == 7)
39 return 0;
40 size_t I = 0;
41 for (; I < Size1 && I < Size2 && I < MaxOutSize; ++I) {
42 Out[I] = std::min(Data1[I], Data2[I]);
43 }
44 return I;
45}
46
47} // extern "C"
48