2021-01-25 12:23:45 +01:00
|
|
|
// Copyright (c) 2020-2021 The Bitcoin Core developers
|
2020-05-25 12:40:36 +00:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
|
|
|
#include <chainparams.h>
|
|
|
|
#include <chainparamsbase.h>
|
|
|
|
#include <net.h>
|
|
|
|
#include <net_permissions.h>
|
|
|
|
#include <netaddress.h>
|
|
|
|
#include <protocol.h>
|
|
|
|
#include <random.h>
|
|
|
|
#include <test/fuzz/FuzzedDataProvider.h>
|
|
|
|
#include <test/fuzz/fuzz.h>
|
|
|
|
#include <test/fuzz/util.h>
|
2020-12-28 21:58:00 +01:00
|
|
|
#include <test/util/net.h>
|
2020-05-25 12:40:36 +00:00
|
|
|
#include <test/util/setup_common.h>
|
2021-09-07 13:31:10 +01:00
|
|
|
#include <util/asmap.h>
|
2020-05-25 12:40:36 +00:00
|
|
|
|
|
|
|
#include <cstdint>
|
2021-03-15 11:59:05 +08:00
|
|
|
#include <optional>
|
2020-05-25 12:40:36 +00:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2020-12-03 16:42:49 +01:00
|
|
|
void initialize_net()
|
2020-05-25 12:40:36 +00:00
|
|
|
{
|
2021-01-25 12:23:45 +01:00
|
|
|
static const auto testing_setup = MakeNoLogFileContext<>(CBaseChainParams::MAIN);
|
2020-05-25 12:40:36 +00:00
|
|
|
}
|
|
|
|
|
2020-12-03 16:42:49 +01:00
|
|
|
FUZZ_TARGET_INIT(net, initialize_net)
|
2020-05-25 12:40:36 +00:00
|
|
|
{
|
|
|
|
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
|
2020-11-19 21:25:14 +00:00
|
|
|
SetMockTime(ConsumeTime(fuzzed_data_provider));
|
2020-12-17 18:49:30 +01:00
|
|
|
CNode node{ConsumeNode(fuzzed_data_provider)};
|
2020-10-12 22:57:37 +02:00
|
|
|
node.SetCommonVersion(fuzzed_data_provider.ConsumeIntegral<int>());
|
2020-05-25 12:40:36 +00:00
|
|
|
while (fuzzed_data_provider.ConsumeBool()) {
|
2021-01-02 13:38:14 +01:00
|
|
|
CallOneOf(
|
|
|
|
fuzzed_data_provider,
|
|
|
|
[&] {
|
|
|
|
node.CloseSocketDisconnect();
|
|
|
|
},
|
|
|
|
[&] {
|
|
|
|
CNodeStats stats;
|
2021-09-01 11:24:46 +01:00
|
|
|
node.CopyStats(stats);
|
2021-01-02 13:38:14 +01:00
|
|
|
},
|
|
|
|
[&] {
|
|
|
|
const CNode* add_ref_node = node.AddRef();
|
|
|
|
assert(add_ref_node == &node);
|
|
|
|
},
|
|
|
|
[&] {
|
|
|
|
if (node.GetRefCount() > 0) {
|
|
|
|
node.Release();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
[&] {
|
|
|
|
const std::optional<CInv> inv_opt = ConsumeDeserializable<CInv>(fuzzed_data_provider);
|
|
|
|
if (!inv_opt) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
node.AddKnownTx(inv_opt->hash);
|
|
|
|
},
|
|
|
|
[&] {
|
|
|
|
node.PushTxInventory(ConsumeUInt256(fuzzed_data_provider));
|
|
|
|
},
|
|
|
|
[&] {
|
|
|
|
const std::optional<CService> service_opt = ConsumeDeserializable<CService>(fuzzed_data_provider);
|
|
|
|
if (!service_opt) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
node.SetAddrLocal(*service_opt);
|
|
|
|
},
|
|
|
|
[&] {
|
|
|
|
const std::vector<uint8_t> b = ConsumeRandomLengthByteVector(fuzzed_data_provider);
|
|
|
|
bool complete;
|
|
|
|
node.ReceiveMsgBytes(b, complete);
|
|
|
|
});
|
2020-05-25 12:40:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
(void)node.GetAddrLocal();
|
|
|
|
(void)node.GetId();
|
|
|
|
(void)node.GetLocalNonce();
|
|
|
|
(void)node.GetLocalServices();
|
|
|
|
const int ref_count = node.GetRefCount();
|
|
|
|
assert(ref_count >= 0);
|
2020-06-05 10:22:53 +03:00
|
|
|
(void)node.GetCommonVersion();
|
2020-05-25 12:40:36 +00:00
|
|
|
|
2020-12-28 21:58:00 +01:00
|
|
|
const NetPermissionFlags net_permission_flags = ConsumeWeakEnum(fuzzed_data_provider, ALL_NET_PERMISSION_FLAGS);
|
2020-05-25 12:40:36 +00:00
|
|
|
(void)node.HasPermission(net_permission_flags);
|
2020-10-03 12:18:36 +03:00
|
|
|
(void)node.ConnectedThroughNetwork();
|
2020-05-25 12:40:36 +00:00
|
|
|
}
|