• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
12 static volatile int Sink;
13 
Recursive(const uint8_t * Data,size_t Size,int Depth)14 void 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 + 1, Size - 1, Depth + 1);
19   Sink++;
20 }
21 
LLVMFuzzerTestOneInput(const uint8_t * Data,size_t Size)22 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
23   Recursive(Data, Size, 0);
24   return 0;
25 }
26 
27