LCOV - code coverage report
Current view: top level - src/test/fuzz - string.cpp (source / functions) Coverage Total Hit
Test: fuzz_coverage.info Lines: 100.0 % 88 88
Test Date: 2024-09-01 05:20:30 Functions: 100.0 % 2 2
Branches: 52.4 % 164 86

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

Generated by: LCOV version 2.0-1