blob: 60de710e829fa58004b1eecc00c732b55784a47d [file] [log] [blame]
Chandler Carruth2946cd72019-01-19 08:50:56 +00001// 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
Kostya Serebryanyd790eff2018-05-10 02:02:41 +00004
5// Find ABCxxFxUxZxxx... (2048+ bytes, 'x' is any byte)
6#include <assert.h>
7#include <cstddef>
8#include <cstdint>
9#include <cstdlib>
10#include <cstring>
11#include <cstdio>
12
13const size_t N = 2048;
14typedef const uint8_t *IN;
15
Kostya Serebryany44edc282018-07-19 22:00:48 +000016static volatile int one = 1;
17
Kostya Serebryanye9c6f062018-05-16 23:26:37 +000018extern "C" {
Kostya Serebryanyd790eff2018-05-10 02:02:41 +000019__attribute__((noinline)) void bad() {
20 fprintf(stderr, "BINGO\n");
Kostya Serebryany44edc282018-07-19 22:00:48 +000021 if (one)
22 abort();
Kostya Serebryanyd790eff2018-05-10 02:02:41 +000023}
24
25__attribute__((noinline)) void f0(IN in) {
26 uint32_t x = in[5] + 251 * in[7] + 251 * 251 * in[9];
27 if (x == 'F' + 251 * 'U' + 251 * 251 * 'Z')
28 bad();
29}
30
31__attribute__((noinline)) void fC(IN in) { if (in[2] == 'C') f0(in); }
32__attribute__((noinline)) void fB(IN in) { if (in[1] == 'B') fC(in); }
33__attribute__((noinline)) void fA(IN in) { if (in[0] == 'A') fB(in); }
34
Kostya Serebryanye9c6f062018-05-16 23:26:37 +000035} // extern "C"
36
Kostya Serebryanyd790eff2018-05-10 02:02:41 +000037extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
38 if (Size < N) return 0;
39 fA((IN)Data);
40 return 0;
41}