1*66df9894Smhl // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
2*66df9894Smhl // See https://llvm.org/LICENSE.txt for license information.
3*66df9894Smhl // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4*66df9894Smhl 
5*66df9894Smhl // Simple test for a cutom mutator that results in long sequences of mutations.
6*66df9894Smhl #include <assert.h>
7*66df9894Smhl #include <cstddef>
8*66df9894Smhl #include <cstdint>
9*66df9894Smhl #include <cstdlib>
10*66df9894Smhl #include <iostream>
11*66df9894Smhl #include <ostream>
12*66df9894Smhl 
13*66df9894Smhl #include "FuzzerInterface.h"
14*66df9894Smhl 
15*66df9894Smhl static volatile int Sink;
16*66df9894Smhl 
LLVMFuzzerTestOneInput(const uint8_t * Data,size_t Size)17*66df9894Smhl extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
18*66df9894Smhl   assert(Data);
19*66df9894Smhl   if (Size > 0 && Data[0] == 'H') {
20*66df9894Smhl     Sink = 1;
21*66df9894Smhl     if (Size > 1 && Data[1] == 'i') {
22*66df9894Smhl       Sink = 2;
23*66df9894Smhl       if (Size > 2 && Data[2] == '!') {
24*66df9894Smhl         std::cout << "BINGO; Found the target, exiting\n"
25*66df9894Smhl                   << std::flush;
26*66df9894Smhl         exit(1);
27*66df9894Smhl       }
28*66df9894Smhl     }
29*66df9894Smhl   }
30*66df9894Smhl   return 0;
31*66df9894Smhl }
32*66df9894Smhl 
LLVMFuzzerCustomMutator(uint8_t * Data,size_t Size,size_t MaxSize,unsigned int Seed)33*66df9894Smhl extern "C" size_t LLVMFuzzerCustomMutator(uint8_t *Data, size_t Size,
34*66df9894Smhl                                           size_t MaxSize, unsigned int Seed) {
35*66df9894Smhl   // Run this 25 times to generate a large mutation sequence.
36*66df9894Smhl   for (size_t i = 0; i < 25; i++) {
37*66df9894Smhl     LLVMFuzzerMutate(Data, Size, MaxSize);
38*66df9894Smhl   }
39*66df9894Smhl   return LLVMFuzzerMutate(Data, Size, MaxSize);
40*66df9894Smhl }
41