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 // Source code for a simple DSO.
6 
7 #include <cstdint>
8 #include <cstdio>
9 #include <cstdlib>
10 #include <cstring>
11 extern int DSO1(int a);
12 extern int DSO2(int a);
13 extern int DSOTestExtra(int a);
14 
15 static volatile int *nil = 0;
16 
LLVMFuzzerTestOneInput(const uint8_t * Data,size_t Size)17 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
18   int x, y, z;
19   if (Size < sizeof(int) * 3) {
20     x = y = z = 0;
21   } else {
22     memcpy(&x, Data + 0 * sizeof(int), sizeof(int));
23     memcpy(&y, Data + 1 * sizeof(int), sizeof(int));
24     memcpy(&z, Data + 2 * sizeof(int), sizeof(int));
25   }
26   int sum = DSO1(x) + DSO2(y) + (z ? DSOTestExtra(z) : 0);
27   if (sum == 3) {
28     fprintf(stderr, "BINGO %d %d %d\n", x, y, z);
29     *nil = 0;
30   }
31   return 0;
32 }
33