Coverage Report

Created: 2024-10-29 12:10

/root/bitcoin/src/test/fuzz/net_permissions.cpp
Line
Count
Source (jump to first uncovered line)
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>
7
#include <test/fuzz/FuzzedDataProvider.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
18
FUZZ_TARGET(net_permissions)
19
0
{
20
0
    FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
21
0
    const std::string s = fuzzed_data_provider.ConsumeRandomLengthString(1000);
22
0
    const NetPermissionFlags net_permission_flags = ConsumeWeakEnum(fuzzed_data_provider, ALL_NET_PERMISSION_FLAGS);
23
24
0
    NetWhitebindPermissions net_whitebind_permissions;
25
0
    bilingual_str error_net_whitebind_permissions;
26
0
    if (NetWhitebindPermissions::TryParse(s, net_whitebind_permissions, error_net_whitebind_permissions)) {
27
0
        (void)NetPermissions::ToStrings(net_whitebind_permissions.m_flags);
28
0
        (void)NetPermissions::AddFlag(net_whitebind_permissions.m_flags, net_permission_flags);
29
0
        assert(NetPermissions::HasFlag(net_whitebind_permissions.m_flags, net_permission_flags));
30
0
        (void)NetPermissions::ClearFlag(net_whitebind_permissions.m_flags, NetPermissionFlags::Implicit);
31
0
        (void)NetPermissions::ToStrings(net_whitebind_permissions.m_flags);
32
0
    }
33
34
0
    NetWhitelistPermissions net_whitelist_permissions;
35
0
    ConnectionDirection connection_direction;
36
0
    bilingual_str error_net_whitelist_permissions;
37
0
    if (NetWhitelistPermissions::TryParse(s, net_whitelist_permissions, connection_direction, error_net_whitelist_permissions)) {
38
0
        (void)NetPermissions::ToStrings(net_whitelist_permissions.m_flags);
39
0
        (void)NetPermissions::AddFlag(net_whitelist_permissions.m_flags, net_permission_flags);
40
0
        assert(NetPermissions::HasFlag(net_whitelist_permissions.m_flags, net_permission_flags));
41
0
        (void)NetPermissions::ClearFlag(net_whitelist_permissions.m_flags, NetPermissionFlags::Implicit);
42
0
        (void)NetPermissions::ToStrings(net_whitelist_permissions.m_flags);
43
0
    }
44
0
}