Bitcoin Core  24.99.0
P2P Digital Currency
net_permissions.cpp
Go to the documentation of this file.
1 // Copyright (c) 2020-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 <net_permissions.h>
7 #include <test/fuzz/fuzz.h>
8 #include <test/fuzz/util.h>
9 #include <util/translation.h>
10 
11 #include <cassert>
12 #include <cstdint>
13 #include <string>
14 #include <vector>
15 
16 FUZZ_TARGET(net_permissions)
17 {
18  FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
19  const std::string s = fuzzed_data_provider.ConsumeRandomLengthString(32);
20  const NetPermissionFlags net_permission_flags = ConsumeWeakEnum(fuzzed_data_provider, ALL_NET_PERMISSION_FLAGS);
21 
22  NetWhitebindPermissions net_whitebind_permissions;
23  bilingual_str error_net_whitebind_permissions;
24  if (NetWhitebindPermissions::TryParse(s, net_whitebind_permissions, error_net_whitebind_permissions)) {
25  (void)NetPermissions::ToStrings(net_whitebind_permissions.m_flags);
26  (void)NetPermissions::AddFlag(net_whitebind_permissions.m_flags, net_permission_flags);
27  assert(NetPermissions::HasFlag(net_whitebind_permissions.m_flags, net_permission_flags));
28  (void)NetPermissions::ClearFlag(net_whitebind_permissions.m_flags, NetPermissionFlags::Implicit);
29  (void)NetPermissions::ToStrings(net_whitebind_permissions.m_flags);
30  }
31 
32  NetWhitelistPermissions net_whitelist_permissions;
33  bilingual_str error_net_whitelist_permissions;
34  if (NetWhitelistPermissions::TryParse(s, net_whitelist_permissions, error_net_whitelist_permissions)) {
35  (void)NetPermissions::ToStrings(net_whitelist_permissions.m_flags);
36  (void)NetPermissions::AddFlag(net_whitelist_permissions.m_flags, net_permission_flags);
37  assert(NetPermissions::HasFlag(net_whitelist_permissions.m_flags, net_permission_flags));
38  (void)NetPermissions::ClearFlag(net_whitelist_permissions.m_flags, NetPermissionFlags::Implicit);
39  (void)NetPermissions::ToStrings(net_whitelist_permissions.m_flags);
40  }
41 }
std::string ConsumeRandomLengthString(size_t max_length)
NetPermissionFlags m_flags
static void AddFlag(NetPermissionFlags &flags, NetPermissionFlags f)
static void ClearFlag(NetPermissionFlags &flags, NetPermissionFlags f)
ClearFlag is only called with f == NetPermissionFlags::Implicit.
static std::vector< std::string > ToStrings(NetPermissionFlags flags)
static bool HasFlag(NetPermissionFlags flags, NetPermissionFlags f)
static bool TryParse(const std::string &str, NetWhitebindPermissions &output, bilingual_str &error)
static bool TryParse(const std::string &str, NetWhitelistPermissions &output, bilingual_str &error)
NetPermissionFlags
Bilingual messages:
Definition: translation.h:18
FUZZ_TARGET(net_permissions)
WeakEnumType ConsumeWeakEnum(FuzzedDataProvider &fuzzed_data_provider, const WeakEnumType(&all_types)[size]) noexcept
Definition: util.h:164
constexpr NetPermissionFlags ALL_NET_PERMISSION_FLAGS[]
Definition: net.h:66
assert(!tx.IsCoinBase())