Line data Source code
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 <test/fuzz/FuzzedDataProvider.h> 7 : #include <test/fuzz/fuzz.h> 8 : #include <test/fuzz/util.h> 9 : #include <test/fuzz/util/net.h> 10 : #include <util/translation.h> 11 : 12 : #include <cassert> 13 : #include <cstdint> 14 : #include <string> 15 : #include <vector> 16 : 17 6 : FUZZ_TARGET(net_permissions) 18 2 : { 19 0 : FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size()); 20 0 : const std::string s = fuzzed_data_provider.ConsumeRandomLengthString(32); 21 0 : const NetPermissionFlags net_permission_flags = ConsumeWeakEnum(fuzzed_data_provider, ALL_NET_PERMISSION_FLAGS); 22 : 23 0 : NetWhitebindPermissions net_whitebind_permissions; 24 0 : bilingual_str error_net_whitebind_permissions; 25 2 : if (NetWhitebindPermissions::TryParse(s, net_whitebind_permissions, error_net_whitebind_permissions)) { 26 0 : (void)NetPermissions::ToStrings(net_whitebind_permissions.m_flags); 27 0 : (void)NetPermissions::AddFlag(net_whitebind_permissions.m_flags, net_permission_flags); 28 0 : assert(NetPermissions::HasFlag(net_whitebind_permissions.m_flags, net_permission_flags)); 29 0 : (void)NetPermissions::ClearFlag(net_whitebind_permissions.m_flags, NetPermissionFlags::Implicit); 30 0 : (void)NetPermissions::ToStrings(net_whitebind_permissions.m_flags); 31 0 : } 32 : 33 0 : NetWhitelistPermissions net_whitelist_permissions; 34 0 : bilingual_str error_net_whitelist_permissions; 35 0 : if (NetWhitelistPermissions::TryParse(s, net_whitelist_permissions, error_net_whitelist_permissions)) { 36 0 : (void)NetPermissions::ToStrings(net_whitelist_permissions.m_flags); 37 0 : (void)NetPermissions::AddFlag(net_whitelist_permissions.m_flags, net_permission_flags); 38 0 : assert(NetPermissions::HasFlag(net_whitelist_permissions.m_flags, net_permission_flags)); 39 0 : (void)NetPermissions::ClearFlag(net_whitelist_permissions.m_flags, NetPermissionFlags::Implicit); 40 0 : (void)NetPermissions::ToStrings(net_whitelist_permissions.m_flags); 41 0 : } 42 0 : }