blob: 74fc939534ca4ce2f1c405b3434ede01b875be45 [file] [log] [blame]
George Karpenkov10ab2ac2017-08-21 23:25:50 +00001// 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
16static volatile int sink;
17
18extern "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
25extern "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}