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
5 // Simple test for a custom crossover.
16 static const char *Separator
= "-########-";
17 static const char *Target
= "A-########-B";
19 static volatile int sink
;
21 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data
, size_t Size
) {
23 std::string
Str(reinterpret_cast<const char *>(Data
), Size
);
24 static const size_t TargetHash
= std::hash
<std::string
>{}(std::string(Target
));
25 size_t StrHash
= std::hash
<std::string
>{}(Str
);
27 // Ensure we have 'A' and 'B' in the corpus.
28 if (Size
== 1 && *Data
== 'A')
30 if (Size
== 1 && *Data
== 'B')
33 if (TargetHash
== StrHash
) {
34 std::cout
<< "BINGO; Found the target, exiting\n" << std::flush
;
40 extern "C" size_t LLVMFuzzerCustomCrossOver(const uint8_t *Data1
, size_t Size1
,
41 const uint8_t *Data2
, size_t Size2
,
42 uint8_t *Out
, size_t MaxOutSize
,
44 static size_t Printed
;
45 static size_t SeparatorLen
= strlen(Separator
);
48 std::cerr
<< "In LLVMFuzzerCustomCrossover " << Size1
<< " " << Size2
<< "\n";
50 size_t Size
= Size1
+ Size2
+ SeparatorLen
;
52 if (Size
> MaxOutSize
)
55 memcpy(Out
, Data1
, Size1
);
56 memcpy(Out
+ Size1
, Separator
, SeparatorLen
);
57 memcpy(Out
+ Size1
+ SeparatorLen
, Data2
, Size2
);