mirror of
https://github.com/bitcoin/bitcoin.git
synced 2024-11-20 02:25:40 +01:00
tests: Add fuzzing harness for functions in net_permissions.h
This commit is contained in:
parent
43ff0d91f8
commit
4308aa67e3
@ -44,6 +44,7 @@ FUZZ_TARGETS = \
|
||||
test/fuzz/merkle_block_deserialize \
|
||||
test/fuzz/messageheader_deserialize \
|
||||
test/fuzz/multiplication_overflow \
|
||||
test/fuzz/net_permissions \
|
||||
test/fuzz/netaddr_deserialize \
|
||||
test/fuzz/netaddress \
|
||||
test/fuzz/out_point_deserialize \
|
||||
@ -530,6 +531,12 @@ test_fuzz_multiplication_overflow_LDADD = $(FUZZ_SUITE_LD_COMMON)
|
||||
test_fuzz_multiplication_overflow_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
|
||||
test_fuzz_multiplication_overflow_SOURCES = $(FUZZ_SUITE) test/fuzz/multiplication_overflow.cpp
|
||||
|
||||
test_fuzz_net_permissions_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
|
||||
test_fuzz_net_permissions_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
|
||||
test_fuzz_net_permissions_LDADD = $(FUZZ_SUITE_LD_COMMON)
|
||||
test_fuzz_net_permissions_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
|
||||
test_fuzz_net_permissions_SOURCES = $(FUZZ_SUITE) test/fuzz/net_permissions.cpp
|
||||
|
||||
test_fuzz_netaddr_deserialize_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) -DNETADDR_DESERIALIZE=1
|
||||
test_fuzz_netaddr_deserialize_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
|
||||
test_fuzz_netaddr_deserialize_LDADD = $(FUZZ_SUITE_LD_COMMON)
|
||||
|
51
src/test/fuzz/net_permissions.cpp
Normal file
51
src/test/fuzz/net_permissions.cpp
Normal file
@ -0,0 +1,51 @@
|
||||
// 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 <net_permissions.h>
|
||||
#include <optional.h>
|
||||
#include <test/fuzz/FuzzedDataProvider.h>
|
||||
#include <test/fuzz/fuzz.h>
|
||||
#include <test/fuzz/util.h>
|
||||
|
||||
#include <cassert>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
void test_one_input(const std::vector<uint8_t>& buffer)
|
||||
{
|
||||
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_ISIMPLICIT,
|
||||
NetPermissionFlags::PF_ALL,
|
||||
}) :
|
||||
static_cast<NetPermissionFlags>(fuzzed_data_provider.ConsumeIntegral<uint32_t>());
|
||||
|
||||
NetWhitebindPermissions net_whitebind_permissions;
|
||||
std::string error_net_whitebind_permissions;
|
||||
if (NetWhitebindPermissions::TryParse(s, net_whitebind_permissions, error_net_whitebind_permissions)) {
|
||||
(void)NetPermissions::ToStrings(net_whitebind_permissions.m_flags);
|
||||
(void)NetPermissions::AddFlag(net_whitebind_permissions.m_flags, net_permission_flags);
|
||||
assert(NetPermissions::HasFlag(net_whitebind_permissions.m_flags, net_permission_flags));
|
||||
(void)NetPermissions::ClearFlag(net_whitebind_permissions.m_flags, net_permission_flags);
|
||||
(void)NetPermissions::ToStrings(net_whitebind_permissions.m_flags);
|
||||
}
|
||||
|
||||
NetWhitelistPermissions net_whitelist_permissions;
|
||||
std::string error_net_whitelist_permissions;
|
||||
if (NetWhitelistPermissions::TryParse(s, net_whitelist_permissions, error_net_whitelist_permissions)) {
|
||||
(void)NetPermissions::ToStrings(net_whitelist_permissions.m_flags);
|
||||
(void)NetPermissions::AddFlag(net_whitelist_permissions.m_flags, net_permission_flags);
|
||||
assert(NetPermissions::HasFlag(net_whitelist_permissions.m_flags, net_permission_flags));
|
||||
(void)NetPermissions::ClearFlag(net_whitelist_permissions.m_flags, net_permission_flags);
|
||||
(void)NetPermissions::ToStrings(net_whitelist_permissions.m_flags);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user