1 /* 2 * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved. 3 * 4 * Licensed under the OpenSSL licenses, (the "License"); 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> 12 #include <stdlib.h> 13 #include <openssl/opensslconf.h> 14 #include "fuzzer.h" 15 16 #ifndef OPENSSL_NO_FUZZ_LIBFUZZER 17 18 int LLVMFuzzerInitialize(int *argc, char ***argv) 19 { 20 if (FuzzerInitialize) 21 return FuzzerInitialize(argc, argv); 22 return 0; 23 } 24 25 int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len) { 26 return FuzzerTestOneInput(buf, len); 27 } 28 29 #elif !defined(OPENSSL_NO_FUZZ_AFL) 30 31 #define BUF_SIZE 65536 32 33 int main(int argc, char** argv) 34 { 35 if (FuzzerInitialize) 36 FuzzerInitialize(&argc, &argv); 37 38 while (__AFL_LOOP(10000)) { 39 uint8_t *buf = malloc(BUF_SIZE); 40 size_t size = read(0, buf, BUF_SIZE); 41 42 FuzzerTestOneInput(buf, size); 43 free(buf); 44 } 45 return 0; 46 } 47 48 #else 49 50 #error "Unsupported fuzzer" 51 52 #endif 53