blob: 076cda0634598c0b74761381ee6004802babc67b [file] [log] [blame]
Kostya Serebryanyd790eff2018-05-10 02:02:41 +00001// This file is distributed under the University of Illinois Open Source
2// License. See LICENSE.TXT for details.
3
4// Find ABCxxFxUxZxxx... (2048+ bytes, 'x' is any byte)
5#include <assert.h>
6#include <cstddef>
7#include <cstdint>
8#include <cstdlib>
9#include <cstring>
10#include <cstdio>
11
12const size_t N = 2048;
13typedef const uint8_t *IN;
14
Kostya Serebryany44edc282018-07-19 22:00:48 +000015static volatile int one = 1;
16
Kostya Serebryanye9c6f062018-05-16 23:26:37 +000017extern "C" {
Kostya Serebryanyd790eff2018-05-10 02:02:41 +000018__attribute__((noinline)) void bad() {
19 fprintf(stderr, "BINGO\n");
Kostya Serebryany44edc282018-07-19 22:00:48 +000020 if (one)
21 abort();
Kostya Serebryanyd790eff2018-05-10 02:02:41 +000022}
23
24__attribute__((noinline)) void f0(IN in) {
25 uint32_t x = in[5] + 251 * in[7] + 251 * 251 * in[9];
26 if (x == 'F' + 251 * 'U' + 251 * 251 * 'Z')
27 bad();
28}
29
30__attribute__((noinline)) void fC(IN in) { if (in[2] == 'C') f0(in); }
31__attribute__((noinline)) void fB(IN in) { if (in[1] == 'B') fC(in); }
32__attribute__((noinline)) void fA(IN in) { if (in[0] == 'A') fB(in); }
33
Kostya Serebryanye9c6f062018-05-16 23:26:37 +000034} // extern "C"
35
Kostya Serebryanyd790eff2018-05-10 02:02:41 +000036extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
37 if (Size < N) return 0;
38 fA((IN)Data);
39 return 0;
40}