Branch data 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 [ + - - + ]: 605 : FUZZ_TARGET(net_permissions) 18 [ + - ]: 173 : { 19 : 86 : FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size()); 20 : 86 : const std::string s = fuzzed_data_provider.ConsumeRandomLengthString(32); 21 : 86 : const NetPermissionFlags net_permission_flags = ConsumeWeakEnum(fuzzed_data_provider, ALL_NET_PERMISSION_FLAGS); 22 : : 23 [ + - ]: 86 : NetWhitebindPermissions net_whitebind_permissions; 24 : 86 : bilingual_str error_net_whitebind_permissions; 25 [ + - + - : 259 : if (NetWhitebindPermissions::TryParse(s, net_whitebind_permissions, error_net_whitebind_permissions)) { + + ] 26 [ + - ]: 5 : (void)NetPermissions::ToStrings(net_whitebind_permissions.m_flags); 27 [ + - ]: 5 : (void)NetPermissions::AddFlag(net_whitebind_permissions.m_flags, net_permission_flags); 28 [ + - + - ]: 5 : assert(NetPermissions::HasFlag(net_whitebind_permissions.m_flags, net_permission_flags)); 29 [ + - ]: 5 : (void)NetPermissions::ClearFlag(net_whitebind_permissions.m_flags, NetPermissionFlags::Implicit); 30 [ + - ]: 5 : (void)NetPermissions::ToStrings(net_whitebind_permissions.m_flags); 31 : 5 : } 32 : : 33 [ + - ]: 86 : NetWhitelistPermissions net_whitelist_permissions; 34 : 86 : bilingual_str error_net_whitelist_permissions; 35 [ + - + + ]: 86 : if (NetWhitelistPermissions::TryParse(s, net_whitelist_permissions, error_net_whitelist_permissions)) { 36 [ + - ]: 18 : (void)NetPermissions::ToStrings(net_whitelist_permissions.m_flags); 37 [ + - ]: 18 : (void)NetPermissions::AddFlag(net_whitelist_permissions.m_flags, net_permission_flags); 38 [ + - - + ]: 18 : assert(NetPermissions::HasFlag(net_whitelist_permissions.m_flags, net_permission_flags)); 39 [ + - ]: 18 : (void)NetPermissions::ClearFlag(net_whitelist_permissions.m_flags, NetPermissionFlags::Implicit); 40 [ + - ]: 18 : (void)NetPermissions::ToStrings(net_whitelist_permissions.m_flags); 41 : 18 : } 42 : 86 : }