Skip to content

Commit fa99e33

Browse files
author
MarcoFalke
committed
fuzz: move-only FillNode implementation to cpp file
This allows to modify the implementation without having to recompile all fuzz targets. Can be reviewed with --color-moved=dimmed-zebra
1 parent 32b191f commit fa99e33

File tree

3 files changed

+24
-16
lines changed

3 files changed

+24
-16
lines changed

src/Makefile.test_fuzz.include

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ libtest_fuzz_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(MINIUPNPC_CPPFLAG
1616
libtest_fuzz_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
1717
libtest_fuzz_a_SOURCES = \
1818
test/fuzz/fuzz.cpp \
19+
test/fuzz/util.cpp \
1920
$(TEST_FUZZ_H)
2021

2122
LIBTEST_FUZZ += $(LIBBITCOIN_SERVER)

src/test/fuzz/util.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright (c) 2021 The Bitcoin Core developers
2+
// Distributed under the MIT software license, see the accompanying
3+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
5+
#include <test/fuzz/util.h>
6+
7+
void FillNode(FuzzedDataProvider& fuzzed_data_provider, CNode& node, const std::optional<int32_t>& version_in) noexcept
8+
{
9+
const ServiceFlags remote_services = ConsumeWeakEnum(fuzzed_data_provider, ALL_SERVICE_FLAGS);
10+
const NetPermissionFlags permission_flags = ConsumeWeakEnum(fuzzed_data_provider, ALL_NET_PERMISSION_FLAGS);
11+
const int32_t version = version_in.value_or(fuzzed_data_provider.ConsumeIntegral<int32_t>());
12+
const bool filter_txs = fuzzed_data_provider.ConsumeBool();
13+
14+
node.nServices = remote_services;
15+
node.m_permissionFlags = permission_flags;
16+
node.nVersion = version;
17+
node.SetCommonVersion(version);
18+
if (node.m_tx_relay != nullptr) {
19+
LOCK(node.m_tx_relay->cs_filter);
20+
node.m_tx_relay->fRelayTxes = filter_txs;
21+
}
22+
}

src/test/fuzz/util.h

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -322,22 +322,7 @@ auto ConsumeNode(FuzzedDataProvider& fuzzed_data_provider, const std::optional<N
322322
}
323323
inline std::unique_ptr<CNode> ConsumeNodeAsUniquePtr(FuzzedDataProvider& fdp, const std::optional<NodeId>& node_id_in = nullopt) { return ConsumeNode<true>(fdp, node_id_in); }
324324

325-
inline void FillNode(FuzzedDataProvider& fuzzed_data_provider, CNode& node, const std::optional<int32_t>& version_in = std::nullopt) noexcept
326-
{
327-
const ServiceFlags remote_services = ConsumeWeakEnum(fuzzed_data_provider, ALL_SERVICE_FLAGS);
328-
const NetPermissionFlags permission_flags = ConsumeWeakEnum(fuzzed_data_provider, ALL_NET_PERMISSION_FLAGS);
329-
const int32_t version = version_in.value_or(fuzzed_data_provider.ConsumeIntegral<int32_t>());
330-
const bool filter_txs = fuzzed_data_provider.ConsumeBool();
331-
332-
node.nServices = remote_services;
333-
node.m_permissionFlags = permission_flags;
334-
node.nVersion = version;
335-
node.SetCommonVersion(version);
336-
if (node.m_tx_relay != nullptr) {
337-
LOCK(node.m_tx_relay->cs_filter);
338-
node.m_tx_relay->fRelayTxes = filter_txs;
339-
}
340-
}
325+
void FillNode(FuzzedDataProvider& fuzzed_data_provider, CNode& node, const std::optional<int32_t>& version_in = std::nullopt) noexcept;
341326

342327
template <class T = const BasicTestingSetup>
343328
std::unique_ptr<T> MakeFuzzingContext(const std::string& chain_name = CBaseChainParams::REGTEST, const std::vector<const char*>& extra_args = {})

0 commit comments

Comments
 (0)