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