blob: 337b8de5eb517590cde4307d6289517a494acd24 [file] [log] [blame]
Kurt Roeckxf59d0132016-05-07 22:09:13 +02001/*
Matt Caswell12128182018-09-11 13:22:14 +01002 * Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved.
Kurt Roeckxf59d0132016-05-07 22:09:13 +02003 *
Richard Levitte06429312018-12-06 14:07:47 +01004 * Licensed under the Apache License 2.0 (the "License");
Kurt Roeckxf59d0132016-05-07 22:09:13 +02005 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 * https://www.openssl.org/source/license.html
8 * or in the file LICENSE in the source distribution.
9 */
10#include <stdint.h>
11#include <unistd.h>
Kurt Roeckx0a320652016-06-05 20:51:04 +020012#include <stdlib.h>
Kurt Roeckxf59d0132016-05-07 22:09:13 +020013#include <openssl/opensslconf.h>
14#include "fuzzer.h"
15
16#ifndef OPENSSL_NO_FUZZ_LIBFUZZER
17
Patrick Steuer63c5ac82018-09-06 15:51:43 +020018int LLVMFuzzerInitialize(int *argc, char ***argv);
19int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len);
20
Kurt Roeckxf59d0132016-05-07 22:09:13 +020021int LLVMFuzzerInitialize(int *argc, char ***argv)
22{
Kurt Roeckxbaae2cb2016-11-19 17:12:11 +010023 return FuzzerInitialize(argc, argv);
Kurt Roeckxf59d0132016-05-07 22:09:13 +020024}
25
Kurt Roeckxf3e911d2016-11-19 17:10:35 +010026int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len)
27{
Kurt Roeckxf59d0132016-05-07 22:09:13 +020028 return FuzzerTestOneInput(buf, len);
29}
30
31#elif !defined(OPENSSL_NO_FUZZ_AFL)
32
33#define BUF_SIZE 65536
34
35int main(int argc, char** argv)
36{
Kurt Roeckxbaae2cb2016-11-19 17:12:11 +010037 FuzzerInitialize(&argc, &argv);
Kurt Roeckxf59d0132016-05-07 22:09:13 +020038
39 while (__AFL_LOOP(10000)) {
40 uint8_t *buf = malloc(BUF_SIZE);
41 size_t size = read(0, buf, BUF_SIZE);
42
43 FuzzerTestOneInput(buf, size);
44 free(buf);
45 }
Kurt Roeckxad4da7f2016-11-19 17:13:10 +010046
47 FuzzerCleanup();
Kurt Roeckxf59d0132016-05-07 22:09:13 +020048 return 0;
49}
50
51#else
52
53#error "Unsupported fuzzer"
54
55#endif