LCOV - code coverage report
Current view: top level - src/test/fuzz - string.cpp (source / functions) Hit Total Coverage
Test: fuzz_coverage.info Lines: 5 89 5.6 %
Date: 2023-11-10 23:46:46 Functions: 1 6 16.7 %
Branches: 4 174 2.3 %

           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 <blockfilter.h>
       6                 :            : #include <clientversion.h>
       7                 :            : #include <common/args.h>
       8                 :            : #include <common/settings.h>
       9                 :            : #include <common/system.h>
      10                 :            : #include <common/url.h>
      11                 :            : #include <netbase.h>
      12                 :            : #include <outputtype.h>
      13                 :            : #include <rpc/client.h>
      14                 :            : #include <rpc/request.h>
      15                 :            : #include <rpc/server.h>
      16                 :            : #include <rpc/util.h>
      17         [ +  - ]:          2 : #include <script/descriptor.h>
      18         [ +  - ]:          2 : #include <script/script.h>
      19                 :            : #include <serialize.h>
      20                 :            : #include <streams.h>
      21                 :            : #include <test/fuzz/FuzzedDataProvider.h>
      22                 :            : #include <test/fuzz/fuzz.h>
      23                 :            : #include <test/fuzz/util.h>
      24                 :            : #include <util/error.h>
      25                 :          2 : #include <util/fees.h>
      26                 :            : #include <util/strencodings.h>
      27                 :          2 : #include <util/string.h>
      28                 :            : #include <util/translation.h>
      29                 :            : 
      30                 :            : #include <cassert>
      31                 :            : #include <cstdint>
      32                 :            : #include <cstdlib>
      33                 :            : #include <ios>
      34                 :            : #include <stdexcept>
      35                 :            : #include <string>
      36                 :            : #include <vector>
      37                 :            : 
      38                 :            : enum class FeeEstimateMode;
      39                 :            : 
      40 [ +  - ][ +  - ]:          6 : FUZZ_TARGET(string)
      41                 :            : {
      42                 :          0 :     FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
      43                 :          0 :     const std::string random_string_1 = fuzzed_data_provider.ConsumeRandomLengthString(32);
      44         [ #  # ]:          0 :     const std::string random_string_2 = fuzzed_data_provider.ConsumeRandomLengthString(32);
      45                 :          0 :     const std::vector<std::string> random_string_vector = ConsumeRandomLengthStringVector(fuzzed_data_provider);
      46                 :            : 
      47         [ #  # ]:          0 :     (void)AmountErrMsg(random_string_1, random_string_2);
      48         [ #  # ]:          0 :     (void)AmountHighWarn(random_string_1);
      49                 :            :     BlockFilterType block_filter_type;
      50         [ #  # ]:          0 :     (void)BlockFilterTypeByName(random_string_1, block_filter_type);
      51 [ #  # ][ #  # ]:          0 :     (void)Capitalize(random_string_1);
      52         [ #  # ]:          0 :     (void)CopyrightHolders(random_string_1);
      53                 :            :     FeeEstimateMode fee_estimate_mode;
      54         [ #  # ]:          0 :     (void)FeeModeFromString(random_string_1, fee_estimate_mode);
      55         [ #  # ]:          0 :     const auto width{fuzzed_data_provider.ConsumeIntegralInRange<size_t>(1, 1000)};
      56 [ #  # ][ #  # ]:          0 :     (void)FormatParagraph(random_string_1, width, fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, width));
      57 [ #  # ][ #  # ]:          0 :     (void)FormatSubVersion(random_string_1, fuzzed_data_provider.ConsumeIntegral<int>(), random_string_vector);
      58         [ #  # ]:          0 :     (void)GetDescriptorChecksum(random_string_1);
      59         [ #  # ]:          0 :     (void)HelpExampleCli(random_string_1, random_string_2);
      60         [ #  # ]:          0 :     (void)HelpExampleRpc(random_string_1, random_string_2);
      61         [ #  # ]:          0 :     (void)HelpMessageGroup(random_string_1);
      62         [ #  # ]:          0 :     (void)HelpMessageOpt(random_string_1, random_string_2);
      63         [ #  # ]:          0 :     (void)IsDeprecatedRPCEnabled(random_string_1);
      64         [ #  # ]:          0 :     (void)Join(random_string_vector, random_string_1);
      65 [ #  # ][ #  # ]:          0 :     (void)JSONRPCError(fuzzed_data_provider.ConsumeIntegral<int>(), random_string_1);
      66                 :          0 :     const common::Settings settings;
      67         [ #  # ]:          0 :     (void)OnlyHasDefaultSectionSetting(settings, random_string_1, random_string_2);
      68         [ #  # ]:          0 :     (void)ParseNetwork(random_string_1);
      69         [ #  # ]:          0 :     (void)ParseOutputType(random_string_1);
      70         [ #  # ]:          0 :     (void)RemovePrefix(random_string_1, random_string_2);
      71         [ #  # ]:          0 :     (void)ResolveErrMsg(random_string_1, random_string_2);
      72                 :            :     try {
      73         [ #  # ]:          0 :         (void)RPCConvertNamedValues(random_string_1, random_string_vector);
      74         [ #  # ]:          0 :     } catch (const std::runtime_error&) {
      75         [ #  # ]:          0 :     }
      76                 :            :     try {
      77         [ #  # ]:          0 :         (void)RPCConvertValues(random_string_1, random_string_vector);
      78         [ #  # ]:          0 :     } catch (const std::runtime_error&) {
      79         [ #  # ]:          0 :     }
      80         [ #  # ]:          0 :     (void)SanitizeString(random_string_1);
      81 [ #  # ][ #  # ]:          0 :     (void)SanitizeString(random_string_1, fuzzed_data_provider.ConsumeIntegralInRange<int>(0, 3));
      82                 :            : #ifndef WIN32
      83         [ #  # ]:          0 :     (void)ShellEscape(random_string_1);
      84                 :            : #endif // WIN32
      85                 :            :     uint16_t port_out;
      86                 :          0 :     std::string host_out;
      87         [ #  # ]:          0 :     SplitHostPort(random_string_1, port_out, host_out);
      88         [ #  # ]:          0 :     (void)TimingResistantEqual(random_string_1, random_string_2);
      89         [ #  # ]:          0 :     (void)ToLower(random_string_1);
      90         [ #  # ]:          0 :     (void)ToUpper(random_string_1);
      91         [ #  # ]:          0 :     (void)TrimString(random_string_1);
      92         [ #  # ]:          0 :     (void)TrimString(random_string_1, random_string_2);
      93         [ #  # ]:          0 :     (void)urlDecode(random_string_1);
      94                 :          0 :     (void)ContainsNoNUL(random_string_1);
      95         [ #  # ]:          0 :     (void)_(random_string_1.c_str());
      96                 :            :     try {
      97 [ #  # ][ #  # ]:          0 :         throw scriptnum_error{random_string_1};
      98         [ #  # ]:          0 :     } catch (const std::runtime_error&) {
      99         [ #  # ]:          0 :     }
     100                 :            : 
     101                 :            :     {
     102         [ #  # ]:          0 :         DataStream data_stream{};
     103                 :          0 :         std::string s;
     104         [ #  # ]:          0 :         auto limited_string = LIMITED_STRING(s, 10);
     105         [ #  # ]:          0 :         data_stream << random_string_1;
     106                 :            :         try {
     107         [ #  # ]:          0 :             data_stream >> limited_string;
     108 [ #  # ][ #  # ]:          0 :             assert(data_stream.empty());
     109         [ #  # ]:          0 :             assert(s.size() <= random_string_1.size());
     110         [ #  # ]:          0 :             assert(s.size() <= 10);
     111         [ #  # ]:          0 :             if (!random_string_1.empty()) {
     112         [ #  # ]:          0 :                 assert(!s.empty());
     113                 :          0 :             }
     114         [ #  # ]:          0 :         } catch (const std::ios_base::failure&) {
     115         [ #  # ]:          0 :         }
     116                 :          0 :     }
     117                 :            :     {
     118         [ #  # ]:          0 :         DataStream data_stream{};
     119         [ #  # ]:          0 :         const auto limited_string = LIMITED_STRING(random_string_1, 10);
     120         [ #  # ]:          0 :         data_stream << limited_string;
     121                 :          0 :         std::string deserialized_string;
     122         [ #  # ]:          0 :         data_stream >> deserialized_string;
     123 [ #  # ][ #  # ]:          0 :         assert(data_stream.empty());
     124         [ #  # ]:          0 :         assert(deserialized_string == random_string_1);
     125                 :          0 :     }
     126                 :            :     {
     127                 :            :         int64_t amount_out;
     128 [ #  # ][ #  # ]:          0 :         (void)ParseFixedPoint(random_string_1, fuzzed_data_provider.ConsumeIntegralInRange<int>(0, 1024), &amount_out);
     129                 :            :     }
     130                 :            :     {
     131 [ #  # ][ #  # ]:          0 :         const auto single_split{SplitString(random_string_1, fuzzed_data_provider.ConsumeIntegral<char>())};
     132         [ #  # ]:          0 :         assert(single_split.size() >= 1);
     133         [ #  # ]:          0 :         const auto any_split{SplitString(random_string_1, random_string_2)};
     134         [ #  # ]:          0 :         assert(any_split.size() >= 1);
     135                 :          0 :     }
     136                 :            :     {
     137 [ #  # ][ #  # ]:          0 :         (void)Untranslated(random_string_1);
     138 [ #  # ][ #  # ]:          0 :         const bilingual_str bs1{random_string_1, random_string_2};
     139 [ #  # ][ #  # ]:          0 :         const bilingual_str bs2{random_string_2, random_string_1};
     140 [ #  # ][ #  # ]:          0 :         (void)(bs1 + bs2);
     141                 :          0 :     }
     142                 :          0 : }

Generated by: LCOV version 1.14