Changeset View
Changeset View
Standalone View
Standalone View
src/test/fuzz/fuzz.cpp
// Copyright (c) 2009-2019 The Bitcoin Core developers | // Copyright (c) 2009-2019 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <test/fuzz/fuzz.h> | #include <test/fuzz/fuzz.h> | ||||
#include <test/util/setup_common.h> | |||||
#include <cstdint> | #include <cstdint> | ||||
#include <unistd.h> | #include <unistd.h> | ||||
#include <vector> | #include <vector> | ||||
const std::function<void(const std::string &)> G_TEST_LOG_FUN{}; | |||||
// Decide if main(...) should be provided: | // Decide if main(...) should be provided: | ||||
// * AFL needs main(...) regardless of platform. | // * AFL needs main(...) regardless of platform. | ||||
// * macOS handles __attribute__((weak)) main(...) poorly when linking | // * macOS handles __attribute__((weak)) main(...) poorly when linking | ||||
// against libFuzzer. See https://github.com/bitcoin/bitcoin/pull/18008 | // against libFuzzer. See https://github.com/bitcoin/bitcoin/pull/18008 | ||||
// for details. | // for details. | ||||
#if defined(__AFL_COMPILER) || !defined(MAC_OSX) | #if defined(__AFL_COMPILER) || !defined(MAC_OSX) | ||||
#define PROVIDE_MAIN_FUNCTION | #define PROVIDE_MAIN_FUNCTION | ||||
#endif | #endif | ||||
#if defined(PROVIDE_MAIN_FUNCTION) | #if defined(PROVIDE_MAIN_FUNCTION) | ||||
static bool read_stdin(std::vector<uint8_t> &data) { | static bool read_stdin(std::vector<uint8_t> &data) { | ||||
uint8_t buffer[1024]; | uint8_t buffer[1024]; | ||||
ssize_t length = 0; | ssize_t length = 0; | ||||
while ((length = read(STDIN_FILENO, buffer, 1024)) > 0) { | while ((length = read(STDIN_FILENO, buffer, 1024)) > 0) { | ||||
data.insert(data.end(), buffer, buffer + length); | data.insert(data.end(), buffer, buffer + length); | ||||
} | } | ||||
return length == 0; | return length == 0; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 47 Lines • Show Last 20 Lines |