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