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