1*e0c4386eSCy Schubert /*
2*e0c4386eSCy Schubert * Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved.
3*e0c4386eSCy Schubert *
4*e0c4386eSCy Schubert * Licensed under the Apache License 2.0 (the "License");
5*e0c4386eSCy Schubert * you may not use this file except in compliance with the License.
6*e0c4386eSCy Schubert * You may obtain a copy of the License at
7*e0c4386eSCy Schubert * https://www.openssl.org/source/license.html
8*e0c4386eSCy Schubert * or in the file LICENSE in the source distribution.
9*e0c4386eSCy Schubert */
10*e0c4386eSCy Schubert #include <stdint.h>
11*e0c4386eSCy Schubert #include <unistd.h>
12*e0c4386eSCy Schubert #include <stdlib.h>
13*e0c4386eSCy Schubert #include <openssl/opensslconf.h>
14*e0c4386eSCy Schubert #include "fuzzer.h"
15*e0c4386eSCy Schubert
16*e0c4386eSCy Schubert #ifndef OPENSSL_NO_FUZZ_LIBFUZZER
17*e0c4386eSCy Schubert
18*e0c4386eSCy Schubert int LLVMFuzzerInitialize(int *argc, char ***argv);
19*e0c4386eSCy Schubert int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len);
20*e0c4386eSCy Schubert
LLVMFuzzerInitialize(int * argc,char *** argv)21*e0c4386eSCy Schubert int LLVMFuzzerInitialize(int *argc, char ***argv)
22*e0c4386eSCy Schubert {
23*e0c4386eSCy Schubert return FuzzerInitialize(argc, argv);
24*e0c4386eSCy Schubert }
25*e0c4386eSCy Schubert
LLVMFuzzerTestOneInput(const uint8_t * buf,size_t len)26*e0c4386eSCy Schubert int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len)
27*e0c4386eSCy Schubert {
28*e0c4386eSCy Schubert return FuzzerTestOneInput(buf, len);
29*e0c4386eSCy Schubert }
30*e0c4386eSCy Schubert
31*e0c4386eSCy Schubert #elif !defined(OPENSSL_NO_FUZZ_AFL)
32*e0c4386eSCy Schubert
33*e0c4386eSCy Schubert #define BUF_SIZE 65536
34*e0c4386eSCy Schubert
main(int argc,char ** argv)35*e0c4386eSCy Schubert int main(int argc, char** argv)
36*e0c4386eSCy Schubert {
37*e0c4386eSCy Schubert FuzzerInitialize(&argc, &argv);
38*e0c4386eSCy Schubert
39*e0c4386eSCy Schubert while (__AFL_LOOP(10000)) {
40*e0c4386eSCy Schubert uint8_t *buf = malloc(BUF_SIZE);
41*e0c4386eSCy Schubert size_t size = read(0, buf, BUF_SIZE);
42*e0c4386eSCy Schubert
43*e0c4386eSCy Schubert FuzzerTestOneInput(buf, size);
44*e0c4386eSCy Schubert free(buf);
45*e0c4386eSCy Schubert }
46*e0c4386eSCy Schubert
47*e0c4386eSCy Schubert FuzzerCleanup();
48*e0c4386eSCy Schubert return 0;
49*e0c4386eSCy Schubert }
50*e0c4386eSCy Schubert
51*e0c4386eSCy Schubert #else
52*e0c4386eSCy Schubert
53*e0c4386eSCy Schubert #error "Unsupported fuzzer"
54*e0c4386eSCy Schubert
55*e0c4386eSCy Schubert #endif
56