mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-25 10:43:19 -03:00
fuzz: Add ConsumeWeakEnum helper, Extract ALL_NET_PERMISSION_FLAGS
This commit is contained in:
parent
faaef9434c
commit
fa9949b914
4 changed files with 24 additions and 15 deletions
|
@ -13,6 +13,7 @@
|
|||
#include <test/fuzz/FuzzedDataProvider.h>
|
||||
#include <test/fuzz/fuzz.h>
|
||||
#include <test/fuzz/util.h>
|
||||
#include <test/util/net.h>
|
||||
#include <test/util/setup_common.h>
|
||||
|
||||
#include <cstdint>
|
||||
|
@ -122,9 +123,7 @@ FUZZ_TARGET_INIT(net, initialize_net)
|
|||
(void)node.GetCommonVersion();
|
||||
(void)node.RelayAddrsWithConn();
|
||||
|
||||
const NetPermissionFlags net_permission_flags = fuzzed_data_provider.ConsumeBool() ?
|
||||
fuzzed_data_provider.PickValueInArray<NetPermissionFlags>({NetPermissionFlags::PF_NONE, NetPermissionFlags::PF_BLOOMFILTER, NetPermissionFlags::PF_RELAY, NetPermissionFlags::PF_FORCERELAY, NetPermissionFlags::PF_NOBAN, NetPermissionFlags::PF_MEMPOOL, NetPermissionFlags::PF_ISIMPLICIT, NetPermissionFlags::PF_ALL}) :
|
||||
static_cast<NetPermissionFlags>(fuzzed_data_provider.ConsumeIntegral<uint32_t>());
|
||||
const NetPermissionFlags net_permission_flags = ConsumeWeakEnum(fuzzed_data_provider, ALL_NET_PERMISSION_FLAGS);
|
||||
(void)node.HasPermission(net_permission_flags);
|
||||
(void)node.ConnectedThroughNetwork();
|
||||
}
|
||||
|
|
|
@ -17,18 +17,7 @@ FUZZ_TARGET(net_permissions)
|
|||
{
|
||||
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
|
||||
const std::string s = fuzzed_data_provider.ConsumeRandomLengthString(32);
|
||||
const NetPermissionFlags net_permission_flags = fuzzed_data_provider.ConsumeBool() ? fuzzed_data_provider.PickValueInArray<NetPermissionFlags>({
|
||||
NetPermissionFlags::PF_NONE,
|
||||
NetPermissionFlags::PF_BLOOMFILTER,
|
||||
NetPermissionFlags::PF_RELAY,
|
||||
NetPermissionFlags::PF_FORCERELAY,
|
||||
NetPermissionFlags::PF_NOBAN,
|
||||
NetPermissionFlags::PF_MEMPOOL,
|
||||
NetPermissionFlags::PF_ADDR,
|
||||
NetPermissionFlags::PF_ISIMPLICIT,
|
||||
NetPermissionFlags::PF_ALL,
|
||||
}) :
|
||||
static_cast<NetPermissionFlags>(fuzzed_data_provider.ConsumeIntegral<uint32_t>());
|
||||
const NetPermissionFlags net_permission_flags = ConsumeWeakEnum(fuzzed_data_provider, ALL_NET_PERMISSION_FLAGS);
|
||||
|
||||
NetWhitebindPermissions net_whitebind_permissions;
|
||||
bilingual_str error_net_whitebind_permissions;
|
||||
|
|
|
@ -87,6 +87,14 @@ template <typename T>
|
|||
return obj;
|
||||
}
|
||||
|
||||
template <typename WeakEnumType, size_t size>
|
||||
[[nodiscard]] WeakEnumType ConsumeWeakEnum(FuzzedDataProvider& fuzzed_data_provider, const WeakEnumType (&all_types)[size]) noexcept
|
||||
{
|
||||
return fuzzed_data_provider.ConsumeBool() ?
|
||||
fuzzed_data_provider.PickValueInArray<WeakEnumType>(all_types) :
|
||||
WeakEnumType(fuzzed_data_provider.ConsumeIntegral<typename std::underlying_type<WeakEnumType>::type>());
|
||||
}
|
||||
|
||||
[[nodiscard]] inline opcodetype ConsumeOpcodeType(FuzzedDataProvider& fuzzed_data_provider) noexcept
|
||||
{
|
||||
return static_cast<opcodetype>(fuzzed_data_provider.ConsumeIntegralInRange<uint32_t>(0, MAX_OPCODE));
|
||||
|
|
|
@ -30,6 +30,19 @@ struct ConnmanTestMsg : public CConnman {
|
|||
bool ReceiveMsgFrom(CNode& node, CSerializedNetMsg& ser_msg) const;
|
||||
};
|
||||
|
||||
constexpr NetPermissionFlags ALL_NET_PERMISSION_FLAGS[]{
|
||||
NetPermissionFlags::PF_NONE,
|
||||
NetPermissionFlags::PF_BLOOMFILTER,
|
||||
NetPermissionFlags::PF_RELAY,
|
||||
NetPermissionFlags::PF_FORCERELAY,
|
||||
NetPermissionFlags::PF_NOBAN,
|
||||
NetPermissionFlags::PF_MEMPOOL,
|
||||
NetPermissionFlags::PF_ADDR,
|
||||
NetPermissionFlags::PF_DOWNLOAD,
|
||||
NetPermissionFlags::PF_ISIMPLICIT,
|
||||
NetPermissionFlags::PF_ALL,
|
||||
};
|
||||
|
||||
constexpr ConnectionType ALL_CONNECTION_TYPES[]{
|
||||
ConnectionType::INBOUND,
|
||||
ConnectionType::OUTBOUND_FULL_RELAY,
|
||||
|
|
Loading…
Add table
Reference in a new issue