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 // Simple test for a fuzzer.
6 // Try to find the target using the indirect caller-callee pairs.
7 #include <cstddef>
8 #include <cstdint>
9 #include <cstdlib>
10 #include <cstring>
11 #include <iostream>
12
13 typedef void (*F)();
14 static F t[256];
15
f34()16 void f34() {
17 std::cerr << "BINGO\n";
18 exit(1);
19 }
f23()20 void f23() { t[(unsigned)'d'] = f34;}
f12()21 void f12() { t[(unsigned)'c'] = f23;}
f01()22 void f01() { t[(unsigned)'b'] = f12;}
f00()23 void f00() {}
24
25 static F t0[256] = {
26 f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00,
27 f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00,
28 f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00,
29 f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00,
30 f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00,
31 f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00,
32 f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00,
33 f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00,
34 f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00,
35 f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00,
36 f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00,
37 f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00,
38 f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00,
39 f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00,
40 f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00,
41 f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00,
42 };
43
LLVMFuzzerTestOneInput(const uint8_t * Data,size_t Size)44 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
45 if (Size < 4) return 0;
46 // Spoof the counters.
47 for (int i = 0; i < 200; i++) {
48 f23();
49 f12();
50 f01();
51 }
52 memcpy(t, t0, sizeof(t));
53 t[(unsigned)'a'] = f01;
54 t[Data[0]]();
55 t[Data[1]]();
56 t[Data[2]]();
57 t[Data[3]]();
58 return 0;
59 }
60
61