1 // This file is distributed under the University of Illinois Open Source
2 // License. See LICENSE.TXT for details.
3 
4 // Tests that deadlocks do not occur when an OOM occurs during symbolization.
5 
6 #include <cassert>
7 #include <cstdint>
8 #include <cstdio>
9 #include <cstdlib>
10 #include <cstring>
11 
12 #include "Bingo.h"
13 
14 volatile unsigned Sink = 0;
15 
16 // Do not inline this function.  We want to trigger NEW_FUNC symbolization when
17 // libFuzzer finds this function.  We use a macro to make the name as long
18 // possible, hoping to increase the time spent in symbolization and increase the
19 // chances of triggering a deadlock.
20 __attribute__((noinline)) void BINGO() {
21   // Busy work.  Inserts a delay here so the deadlock is more likely to trigger.
22   for (unsigned i = 0; i < 330000000; i++) Sink += i;
23 }
24 
25 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
26   assert(Data);
27   if (Size < 3) return 0;
28   if (Data[0] == 'F' &&
29       Data[1] == 'U' &&
30       Data[2] == 'Z')
31     BINGO();
32   return 0;
33 }
34 
35