mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-02-16 02:18:53 +00:00
Previously, the {Basic,}TestingSetup for fuzzers were set up in many ways:
1. Calling InitializeFuzzingContext, which implicitly constructs a static
const BasicTestingSetup
2. Directly constructing a static const BasicTestingSetup in the initialize_*
function
3. Directly constructing a static TestingSetup and reproducing the
initialization arguments (I'm assuming because
InitializeFuzzingContext only initializes a BasicTestingSetup)
The new, relatively-simple MakeFuzzingContext function allows us to
consolidate these methods of initialization by being flexible enough to
be used in all situations. It:
1. Is templated so that we can choose to initialize any of
the *TestingSetup classes
2. Has sane defaults which are often used in fuzzers but are also
easily overridable
3. Returns a unique_ptr, explicitly transferring ownership to the caller
to deal with according to its situation
26 lines
758 B
C++
26 lines
758 B
C++
// Copyright (c) 2020 The Bitcoin Core developers
|
|
// Distributed under the MIT software license, see the accompanying
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
#include <addrman.h>
|
|
#include <net.h>
|
|
#include <test/fuzz/FuzzedDataProvider.h>
|
|
#include <test/fuzz/fuzz.h>
|
|
#include <test/fuzz/util.h>
|
|
|
|
#include <cstdint>
|
|
#include <vector>
|
|
|
|
void initialize_data_stream_addr_man()
|
|
{
|
|
static const auto testing_setup = MakeFuzzingContext<>();
|
|
}
|
|
|
|
FUZZ_TARGET_INIT(data_stream_addr_man, initialize_data_stream_addr_man)
|
|
{
|
|
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
|
|
CDataStream data_stream = ConsumeDataStream(fuzzed_data_provider);
|
|
CAddrMan addr_man;
|
|
CAddrDB::Read(addr_man, data_stream);
|
|
}
|