11cb0ef41Sopenharmony_ci/*
21cb0ef41Sopenharmony_ci * Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved.
31cb0ef41Sopenharmony_ci *
41cb0ef41Sopenharmony_ci * Licensed under the Apache License 2.0 (the "License");
51cb0ef41Sopenharmony_ci * you may not use this file except in compliance with the License.
61cb0ef41Sopenharmony_ci * You may obtain a copy of the License at
71cb0ef41Sopenharmony_ci * https://www.openssl.org/source/license.html
81cb0ef41Sopenharmony_ci * or in the file LICENSE in the source distribution.
91cb0ef41Sopenharmony_ci */
101cb0ef41Sopenharmony_ci#include <stdint.h>
111cb0ef41Sopenharmony_ci#include <unistd.h>
121cb0ef41Sopenharmony_ci#include <stdlib.h>
131cb0ef41Sopenharmony_ci#include <openssl/opensslconf.h>
141cb0ef41Sopenharmony_ci#include "fuzzer.h"
151cb0ef41Sopenharmony_ci
161cb0ef41Sopenharmony_ci#ifndef OPENSSL_NO_FUZZ_LIBFUZZER
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_ciint LLVMFuzzerInitialize(int *argc, char ***argv);
191cb0ef41Sopenharmony_ciint LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len);
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_ciint LLVMFuzzerInitialize(int *argc, char ***argv)
221cb0ef41Sopenharmony_ci{
231cb0ef41Sopenharmony_ci    return FuzzerInitialize(argc, argv);
241cb0ef41Sopenharmony_ci}
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_ciint LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len)
271cb0ef41Sopenharmony_ci{
281cb0ef41Sopenharmony_ci    return FuzzerTestOneInput(buf, len);
291cb0ef41Sopenharmony_ci}
301cb0ef41Sopenharmony_ci
311cb0ef41Sopenharmony_ci#elif !defined(OPENSSL_NO_FUZZ_AFL)
321cb0ef41Sopenharmony_ci
331cb0ef41Sopenharmony_ci#define BUF_SIZE 65536
341cb0ef41Sopenharmony_ci
351cb0ef41Sopenharmony_ciint main(int argc, char** argv)
361cb0ef41Sopenharmony_ci{
371cb0ef41Sopenharmony_ci    FuzzerInitialize(&argc, &argv);
381cb0ef41Sopenharmony_ci
391cb0ef41Sopenharmony_ci    while (__AFL_LOOP(10000)) {
401cb0ef41Sopenharmony_ci        uint8_t *buf = malloc(BUF_SIZE);
411cb0ef41Sopenharmony_ci        size_t size = read(0, buf, BUF_SIZE);
421cb0ef41Sopenharmony_ci
431cb0ef41Sopenharmony_ci        FuzzerTestOneInput(buf, size);
441cb0ef41Sopenharmony_ci        free(buf);
451cb0ef41Sopenharmony_ci    }
461cb0ef41Sopenharmony_ci
471cb0ef41Sopenharmony_ci    FuzzerCleanup();
481cb0ef41Sopenharmony_ci    return 0;
491cb0ef41Sopenharmony_ci}
501cb0ef41Sopenharmony_ci
511cb0ef41Sopenharmony_ci#else
521cb0ef41Sopenharmony_ci
531cb0ef41Sopenharmony_ci#error "Unsupported fuzzer"
541cb0ef41Sopenharmony_ci
551cb0ef41Sopenharmony_ci#endif
56