Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [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 |
George Karpenkov | 10ab2ac | 2017-08-21 23:25:50 +0000 | [diff] [blame] | 4 | |
George Karpenkov | 10ab2ac | 2017-08-21 23:25:50 +0000 | [diff] [blame] | 5 | #include <stdint.h> |
| 6 | #include <stdio.h> |
| 7 | #include <stdlib.h> |
| 8 | |
Jonathan Metzman | 139e216 | 2019-04-18 18:49:11 +0000 | [diff] [blame] | 9 | // Dummy functions used to avoid dependency on AFL. |
George Karpenkov | 10ab2ac | 2017-08-21 23:25:50 +0000 | [diff] [blame] | 10 | extern "C" void __afl_manual_init() {} |
| 11 | |
| 12 | extern "C" int __afl_persistent_loop(unsigned int N) { |
| 13 | static int Count = N; |
Jonathan Metzman | 139e216 | 2019-04-18 18:49:11 +0000 | [diff] [blame] | 14 | fprintf(stderr, "__afl_persistent_loop called, Count = %d\n", Count); |
| 15 | return Count--; |
George Karpenkov | 10ab2ac | 2017-08-21 23:25:50 +0000 | [diff] [blame] | 16 | } |
| 17 | |
| 18 | // This declaration exists to prevent the Darwin linker |
| 19 | // from complaining about this being a missing weak symbol. |
| 20 | extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv) { |
George Karpenkov | 10ab2ac | 2017-08-21 23:25:50 +0000 | [diff] [blame] | 21 | return 0; |
| 22 | } |
| 23 | |
| 24 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { |
Jonathan Metzman | 139e216 | 2019-04-18 18:49:11 +0000 | [diff] [blame] | 25 | puts("STDOUT MESSAGE"); |
| 26 | fflush(stdout); |
| 27 | fprintf(stderr, "STDERR MESSAGE\n" |
| 28 | "LLVMFuzzerTestOneInput called; Size = %zd\n", |
| 29 | Size); |
| 30 | if (Size < 4) |
| 31 | return 0; |
| 32 | |
| 33 | return Data[Size]; |
George Karpenkov | 10ab2ac | 2017-08-21 23:25:50 +0000 | [diff] [blame] | 34 | } |