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// Test that libFuzzer does not crash when LLVMFuzzerMutate called from
6// LLVMFuzzerCustomCrossOver.
7#include <algorithm>
8#include <cstddef>
9#include <cstdint>
10#include <cstdlib>
11#include <string.h>
12#include <string>
13#include <vector>
14
15#include "FuzzerInterface.h"
16
17static volatile int sink;
18
19extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
20 std::string Str(reinterpret_cast<const char *>(Data), Size);
21 if (Size && Data[0] == '0')
22 sink++;
23 return 0;
24}
25
26extern "C" size_t LLVMFuzzerCustomCrossOver(const uint8_t *Data1, size_t Size1,
27 const uint8_t *Data2, size_t Size2,
28 uint8_t *Out, size_t MaxOutSize,
29 unsigned int Seed) {
30 std::vector<uint8_t> Buffer(MaxOutSize * 10);
31 LLVMFuzzerMutate(Buffer.data(), Buffer.size(), Buffer.size());
32 size_t Size = std::min(Size1, MaxOutSize);
33 memcpy(Out, Data1, Size);
34 return Size;
35}
36