Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 | [diff] [blame] | 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 |
Kostya Serebryany | d790eff | 2018-05-10 02:02:41 | [diff] [blame] | 4 | |
| 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 | |
| 13 | const size_t N = 2048; |
| 14 | typedef const uint8_t *IN; |
| 15 | |
Kostya Serebryany | 44edc28 | 2018-07-19 22:00:48 | [diff] [blame] | 16 | static volatile int one = 1; |
| 17 | |
Kostya Serebryany | e9c6f06 | 2018-05-16 23:26:37 | [diff] [blame] | 18 | extern "C" { |
Kostya Serebryany | d790eff | 2018-05-10 02:02:41 | [diff] [blame] | 19 | __attribute__((noinline)) void bad() { |
| 20 | fprintf(stderr, "BINGO\n"); |
Kostya Serebryany | 44edc28 | 2018-07-19 22:00:48 | [diff] [blame] | 21 | if (one) |
| 22 | abort(); |
Kostya Serebryany | d790eff | 2018-05-10 02:02:41 | [diff] [blame] | 23 | } |
| 24 | |
| 25 | __attribute__((noinline)) void f0(IN in) { |
| 26 | uint32_t x = in[5] + 251 * in[7] + 251 * 251 * in[9]; |
Kostya Serebryany | e9aaa55 | 2019-05-09 21:29:45 | [diff] [blame] | 27 | if (x == 'F' + 251 * 'U' + 251 * 251 * 'Z') { |
| 28 | // artificially inflate uncovered control in f0 |
| 29 | // so that auto-focus is more likely to chose this function. |
| 30 | if (one == -1) { |
| 31 | if (one == 2) one = 1; if (one == 3) one = 1; if (one == 4) one = 1; |
| 32 | if (one == 5) one = 1; if (one == 6) one = 1; if (one == 7) one = 1; |
| 33 | if (one == 8) one = 1; if (one == 9) one = 1; if (one == 0) one = 1; |
| 34 | } |
Kostya Serebryany | d790eff | 2018-05-10 02:02:41 | [diff] [blame] | 35 | bad(); |
Kostya Serebryany | e9aaa55 | 2019-05-09 21:29:45 | [diff] [blame] | 36 | } |
Kostya Serebryany | d790eff | 2018-05-10 02:02:41 | [diff] [blame] | 37 | } |
| 38 | |
Kostya Serebryany | 3f39123 | 2019-06-14 19:54:32 | [diff] [blame^] | 39 | __attribute__((noinline)) void fD(IN in) { f0(in); } |
| 40 | __attribute__((noinline)) void fC(IN in) { if (in[2] == 'C') fD(in); } |
Kostya Serebryany | d790eff | 2018-05-10 02:02:41 | [diff] [blame] | 41 | __attribute__((noinline)) void fB(IN in) { if (in[1] == 'B') fC(in); } |
| 42 | __attribute__((noinline)) void fA(IN in) { if (in[0] == 'A') fB(in); } |
| 43 | |
Kostya Serebryany | e9c6f06 | 2018-05-16 23:26:37 | [diff] [blame] | 44 | } // extern "C" |
| 45 | |
Kostya Serebryany | d790eff | 2018-05-10 02:02:41 | [diff] [blame] | 46 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { |
| 47 | if (Size < N) return 0; |
| 48 | fA((IN)Data); |
| 49 | return 0; |
| 50 | } |