blob: 5f66ac8b499e6cfd37042cc07649c094b5addb1a [file] [log] [blame]
Inna Palantff3f07a2019-07-11 16:15:26 -07001// This file is distributed under the University of Illinois Open Source
2// License. See LICENSE.TXT for details.
3
4// Simple test for a fuzzer. The fuzzer must find the interesting switch value.
5#include <cstddef>
6#include <cstdint>
7#include <cstdio>
8#include <cstdlib>
9#include <cstring>
10
11int Switch(int a) {
12 switch(a) {
13 case 100001: return 1;
14 case 100002: return 2;
15 case 100003: return 4;
16 }
17 return 0;
18}
19
20extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
21 const int N = 3;
22 if (Size < N * sizeof(int)) return 0;
23 int Res = 0;
24 for (int i = 0; i < N; i++) {
25 int X;
26 memcpy(&X, Data + i * sizeof(int), sizeof(int));
27 Res += Switch(X);
28 }
29 if (Res == 5 || Res == 3 || Res == 6 || Res == 7) {
30 fprintf(stderr, "BINGO; Found the target, exiting; Res=%d\n", Res);
31 exit(1);
32 }
33 return 0;
34}
35