Kurt Roeckx | f59d013 | 2016-05-07 22:09:13 +0200 | [diff] [blame] | 1 | /* |
Matt Caswell | 1212818 | 2018-09-11 13:22:14 +0100 | [diff] [blame] | 2 | * Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved. |
Kurt Roeckx | f59d013 | 2016-05-07 22:09:13 +0200 | [diff] [blame] | 3 | * |
Richard Levitte | 0642931 | 2018-12-06 14:07:47 +0100 | [diff] [blame] | 4 | * Licensed under the Apache License 2.0 (the "License"); |
Kurt Roeckx | f59d013 | 2016-05-07 22:09:13 +0200 | [diff] [blame] | 5 | * 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 Roeckx | 0a32065 | 2016-06-05 20:51:04 +0200 | [diff] [blame] | 12 | #include <stdlib.h> |
Kurt Roeckx | f59d013 | 2016-05-07 22:09:13 +0200 | [diff] [blame] | 13 | #include <openssl/opensslconf.h> |
| 14 | #include "fuzzer.h" |
| 15 | |
| 16 | #ifndef OPENSSL_NO_FUZZ_LIBFUZZER |
| 17 | |
Patrick Steuer | 63c5ac8 | 2018-09-06 15:51:43 +0200 | [diff] [blame] | 18 | int LLVMFuzzerInitialize(int *argc, char ***argv); |
| 19 | int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len); |
| 20 | |
Kurt Roeckx | f59d013 | 2016-05-07 22:09:13 +0200 | [diff] [blame] | 21 | int LLVMFuzzerInitialize(int *argc, char ***argv) |
| 22 | { |
Kurt Roeckx | baae2cb | 2016-11-19 17:12:11 +0100 | [diff] [blame] | 23 | return FuzzerInitialize(argc, argv); |
Kurt Roeckx | f59d013 | 2016-05-07 22:09:13 +0200 | [diff] [blame] | 24 | } |
| 25 | |
Kurt Roeckx | f3e911d | 2016-11-19 17:10:35 +0100 | [diff] [blame] | 26 | int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len) |
| 27 | { |
Kurt Roeckx | f59d013 | 2016-05-07 22:09:13 +0200 | [diff] [blame] | 28 | return FuzzerTestOneInput(buf, len); |
| 29 | } |
| 30 | |
| 31 | #elif !defined(OPENSSL_NO_FUZZ_AFL) |
| 32 | |
| 33 | #define BUF_SIZE 65536 |
| 34 | |
| 35 | int main(int argc, char** argv) |
| 36 | { |
Kurt Roeckx | baae2cb | 2016-11-19 17:12:11 +0100 | [diff] [blame] | 37 | FuzzerInitialize(&argc, &argv); |
Kurt Roeckx | f59d013 | 2016-05-07 22:09:13 +0200 | [diff] [blame] | 38 | |
| 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 Roeckx | ad4da7f | 2016-11-19 17:13:10 +0100 | [diff] [blame] | 46 | |
| 47 | FuzzerCleanup(); |
Kurt Roeckx | f59d013 | 2016-05-07 22:09:13 +0200 | [diff] [blame] | 48 | return 0; |
| 49 | } |
| 50 | |
| 51 | #else |
| 52 | |
| 53 | #error "Unsupported fuzzer" |
| 54 | |
| 55 | #endif |