blob: 84b5f9f6ba26c7925b73d9d1e306c14b8ea8714e [file] [log] [blame]
Chandler Carruth2946cd72019-01-19 08:50:56 +00001// 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 Karpenkov10ab2ac2017-08-21 23:25:50 +00004
George Karpenkov10ab2ac2017-08-21 23:25:50 +00005#include <stdint.h>
6#include <stdio.h>
7#include <stdlib.h>
8
Jonathan Metzman139e2162019-04-18 18:49:11 +00009// Dummy functions used to avoid dependency on AFL.
George Karpenkov10ab2ac2017-08-21 23:25:50 +000010extern "C" void __afl_manual_init() {}
11
12extern "C" int __afl_persistent_loop(unsigned int N) {
13 static int Count = N;
Jonathan Metzman139e2162019-04-18 18:49:11 +000014 fprintf(stderr, "__afl_persistent_loop called, Count = %d\n", Count);
15 return Count--;
George Karpenkov10ab2ac2017-08-21 23:25:50 +000016}
17
18// This declaration exists to prevent the Darwin linker
19// from complaining about this being a missing weak symbol.
20extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv) {
George Karpenkov10ab2ac2017-08-21 23:25:50 +000021 return 0;
22}
23
24extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
Jonathan Metzman139e2162019-04-18 18:49:11 +000025 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 Karpenkov10ab2ac2017-08-21 23:25:50 +000034}