LLVM  5.0.0
CustomCrossOverAndMutateTest.cpp
Go to the documentation of this file.
1 // This file is distributed under the University of Illinois Open Source
2 // License. See LICENSE.TXT for details.
3 
4 // Test that libFuzzer does not crash when LLVMFuzzerMutate called from
5 // LLVMFuzzerCustomCrossOver.
6 #include <algorithm>
7 #include <cstddef>
8 #include <cstdint>
9 #include <cstdlib>
10 #include <string.h>
11 #include <string>
12 #include <vector>
13 
14 #include "FuzzerInterface.h"
15 
16 static volatile int sink;
17 
18 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
19  std::string Str(reinterpret_cast<const char *>(Data), Size);
20  if (Size && Data[0] == '0')
21  sink++;
22  return 0;
23 }
24 
25 extern "C" size_t LLVMFuzzerCustomCrossOver(const uint8_t *Data1, size_t Size1,
26  const uint8_t *Data2, size_t Size2,
27  uint8_t *Out, size_t MaxOutSize,
28  unsigned int Seed) {
29  std::vector<uint8_t> Buffer(MaxOutSize * 10);
30  LLVMFuzzerMutate(Buffer.data(), Buffer.size(), Buffer.size());
31  size_t Size = std::min(Size1, MaxOutSize);
32  memcpy(Out, Data1, Size);
33  return Size;
34 }
static cl::opt< unsigned long long > Seed("rng-seed", cl::value_desc("seed"), cl::desc("Seed for the random number generator"), cl::init(0))
Maximum length of the test input libFuzzer tries to guess a good value based on the corpus and reports it always prefer smaller inputs during the corpus shuffle When libFuzzer itself reports a bug this exit code will be used If indicates the maximal total time in seconds to run the fuzzer minimizes the provided crash input Use with tries to cleanse the provided crash input to make it contain fewer original bytes Use with exact_artifact_path to specify the output Experimental Use value profile to guide fuzzing Number of jobs to run If min(jobs, NumberOfCpuCores()/2)\" is used.") FUZZER_FLAG_INT(reload
size_t LLVMFuzzerMutate(uint8_t *Data, size_t Size, size_t MaxSize)
Definition: afl_driver.cpp:248
size_t LLVMFuzzerCustomCrossOver(const uint8_t *Data1, size_t Size1, const uint8_t *Data2, size_t Size2, uint8_t *Out, size_t MaxOutSize, unsigned int Seed)
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
static volatile int sink