mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-15 22:32:37 -03:00
77b79fa6ef
- Move the decision whether to translate an error message to where it is defined. This simplifies call sites: no more `InitError(Untranslated(...))`. - Make all functions in `util/error.h` consistently return a `bilingual_str`. We've decided to use this as error message type so let's roll with it. This has no functional changes: no messages are changed, no new translation messages are defined.
51 lines
3.3 KiB
C++
51 lines
3.3 KiB
C++
// 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 <test/fuzz/FuzzedDataProvider.h>
|
|
#include <test/fuzz/fuzz.h>
|
|
#include <test/fuzz/util.h>
|
|
#include <util/translation.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;
|
|
bilingual_str 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;
|
|
bilingual_str 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);
|
|
}
|
|
}
|