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// Simple test for a fuzzer. The fuzzer must find the deep recursion.
6// To generate a crashy input:
7// for((i=0;i<110;i++)); do echo -n ABCDEFGHIJ >> INPUT; done
8#include <cstddef>
9#include <cstdint>
10#include <cstdlib>
11
12static volatile int Sink;
13
14void Recursive(const uint8_t *Data, size_t Size, int Depth) {
15 if (Depth > 1000) abort();
16 if (!Size) return;
17 if (*Data == ('A' + Depth % 10))
18 Recursive(Data: Data + 1, Size: Size - 1, Depth: Depth + 1);
19 Sink++;
20}
21
22extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
23 Recursive(Data, Size, Depth: 0);
24 return 0;
25}
26
27

source code of compiler-rt/test/fuzzer/DeepRecursionTest.cpp