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