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/fees.h>
26 : : #include <util/strencodings.h>
27 : : #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 : : using common::AmountErrMsg;
39 : : using common::AmountHighWarn;
40 : : using common::FeeModeFromString;
41 : : using common::ResolveErrMsg;
42 : : using util::ContainsNoNUL;
43 : : using util::Join;
44 : : using util::RemovePrefix;
45 : : using util::SplitString;
46 : : using util::TrimString;
47 : :
48 [ + - ]: 2081 : FUZZ_TARGET(string)
49 : : {
50 : 1625 : FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
51 : 1625 : const std::string random_string_1 = fuzzed_data_provider.ConsumeRandomLengthString(32);
52 [ + - ]: 1625 : const std::string random_string_2 = fuzzed_data_provider.ConsumeRandomLengthString(32);
53 : 1625 : const std::vector<std::string> random_string_vector = ConsumeRandomLengthStringVector(fuzzed_data_provider);
54 : :
55 [ + - ]: 1625 : (void)AmountErrMsg(random_string_1, random_string_2);
56 [ + - ]: 1625 : (void)AmountHighWarn(random_string_1);
57 : 1625 : BlockFilterType block_filter_type;
58 [ - + + - ]: 1625 : (void)BlockFilterTypeByName(random_string_1, block_filter_type);
59 [ - + + - ]: 4875 : (void)Capitalize(random_string_1);
60 [ + - ]: 1625 : (void)CopyrightHolders(random_string_1);
61 : 1625 : FeeEstimateMode fee_estimate_mode;
62 [ - + + - ]: 1625 : (void)FeeModeFromString(random_string_1, fee_estimate_mode);
63 : 1625 : const auto width{fuzzed_data_provider.ConsumeIntegralInRange<size_t>(1, 1000)};
64 [ - + + - ]: 1625 : (void)FormatParagraph(random_string_1, width, fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, width));
65 [ + - ]: 1625 : (void)FormatSubVersion(random_string_1, fuzzed_data_provider.ConsumeIntegral<int>(), random_string_vector);
66 [ + - ]: 1625 : (void)GetDescriptorChecksum(random_string_1);
67 [ + - ]: 1625 : (void)HelpExampleCli(random_string_1, random_string_2);
68 [ + - ]: 1625 : (void)HelpExampleRpc(random_string_1, random_string_2);
69 [ + - ]: 1625 : (void)HelpMessageGroup(random_string_1);
70 [ + - ]: 1625 : (void)HelpMessageOpt(random_string_1, random_string_2);
71 [ + - ]: 1625 : (void)IsDeprecatedRPCEnabled(random_string_1);
72 [ + - ]: 1625 : (void)Join(random_string_vector, random_string_1);
73 [ + - ]: 1625 : (void)JSONRPCError(fuzzed_data_provider.ConsumeIntegral<int>(), random_string_1);
74 : 1625 : const common::Settings settings;
75 [ + - ]: 1625 : (void)OnlyHasDefaultSectionSetting(settings, random_string_1, random_string_2);
76 [ + - ]: 1625 : (void)ParseNetwork(random_string_1);
77 [ - + + - ]: 1625 : (void)ParseOutputType(random_string_1);
78 [ - + - + : 1625 : (void)RemovePrefix(random_string_1, random_string_2);
+ - ]
79 [ + - ]: 1625 : (void)ResolveErrMsg(random_string_1, random_string_2);
80 : 1625 : try {
81 [ + + ]: 1625 : (void)RPCConvertNamedValues(random_string_1, random_string_vector);
82 [ - + ]: 957 : } catch (const std::runtime_error&) {
83 : 957 : }
84 : 1625 : try {
85 [ + + ]: 1625 : (void)RPCConvertValues(random_string_1, random_string_vector);
86 [ - + ]: 1010 : } catch (const std::runtime_error&) {
87 : 1010 : }
88 [ - + + - ]: 1625 : (void)SanitizeString(random_string_1);
89 [ - + + - ]: 1625 : (void)SanitizeString(random_string_1, fuzzed_data_provider.ConsumeIntegralInRange<int>(0, 3));
90 : : #ifndef WIN32
91 [ + - ]: 1625 : (void)ShellEscape(random_string_1);
92 : : #endif // WIN32
93 : 1625 : uint16_t port_out;
94 [ - + ]: 1625 : std::string host_out;
95 [ - + + - ]: 1625 : SplitHostPort(random_string_1, port_out, host_out);
96 : 1625 : (void)TimingResistantEqual(random_string_1, random_string_2);
97 [ - + + - ]: 1625 : (void)ToLower(random_string_1);
98 [ - + + - ]: 1625 : (void)ToUpper(random_string_1);
99 [ - + + - ]: 1625 : (void)TrimString(random_string_1);
100 [ - + - + : 1625 : (void)TrimString(random_string_1, random_string_2);
+ - ]
101 [ - + + - ]: 1625 : (void)UrlDecode(random_string_1);
102 [ - + ]: 1625 : (void)ContainsNoNUL(random_string_1);
103 : 1625 : try {
104 [ + - ]: 1625 : throw scriptnum_error{random_string_1};
105 [ - + ]: 1625 : } catch (const std::runtime_error&) {
106 : 1625 : }
107 : :
108 : 1625 : {
109 : 1625 : DataStream data_stream{};
110 [ + - ]: 1625 : std::string s;
111 [ + - ]: 1625 : auto limited_string = LIMITED_STRING(s, 10);
112 [ + - ]: 1625 : data_stream << random_string_1;
113 : 1625 : try {
114 [ + + ]: 1625 : data_stream >> limited_string;
115 [ - + - + ]: 1021 : assert(data_stream.empty());
116 [ - + - + : 1021 : assert(s.size() <= random_string_1.size());
- + ]
117 [ - + ]: 1021 : assert(s.size() <= 10);
118 [ + + ]: 1021 : if (!random_string_1.empty()) {
119 [ - + ]: 971 : assert(!s.empty());
120 : : }
121 [ - + ]: 604 : } catch (const std::ios_base::failure&) {
122 : 604 : }
123 : 1625 : }
124 : 1625 : {
125 : 1625 : DataStream data_stream{};
126 [ + - ]: 1625 : const auto limited_string = LIMITED_STRING(random_string_1, 10);
127 [ + - ]: 1625 : data_stream << limited_string;
128 [ + - ]: 1625 : std::string deserialized_string;
129 [ + - ]: 1625 : data_stream >> deserialized_string;
130 [ - + - + ]: 1625 : assert(data_stream.empty());
131 [ - + ]: 1625 : assert(deserialized_string == random_string_1);
132 : 3250 : }
133 : 1625 : {
134 : 1625 : int64_t amount_out;
135 [ - + + - ]: 1625 : (void)ParseFixedPoint(random_string_1, fuzzed_data_provider.ConsumeIntegralInRange<int>(0, 1024), &amount_out);
136 : : }
137 : 1625 : {
138 [ - + + - ]: 1625 : const auto single_split{SplitString(random_string_1, fuzzed_data_provider.ConsumeIntegral<char>())};
139 [ - + - + ]: 1625 : assert(single_split.size() >= 1);
140 [ - + - + : 1625 : const auto any_split{SplitString(random_string_1, random_string_2)};
+ - ]
141 [ - + - + ]: 1625 : assert(any_split.size() >= 1);
142 : 1625 : }
143 : 1625 : {
144 [ - + + - ]: 4875 : (void)Untranslated(random_string_1);
145 [ - + - + ]: 3250 : const bilingual_str bs1{random_string_1, random_string_2};
146 [ - + - + ]: 3250 : const bilingual_str bs2{random_string_2, random_string_1};
147 [ + - ]: 6500 : (void)(bs1 + bs2);
148 : 1625 : }
149 : 1625 : {
150 : 1625 : const ByteUnit all_units[] = {
151 : : ByteUnit::NOOP,
152 : : ByteUnit::k,
153 : : ByteUnit::K,
154 : : ByteUnit::m,
155 : : ByteUnit::M,
156 : : ByteUnit::g,
157 : : ByteUnit::G,
158 : : ByteUnit::t,
159 : : ByteUnit::T
160 : : };
161 : 1625 : ByteUnit default_multiplier = fuzzed_data_provider.PickValueInArray(all_units);
162 [ - + + - ]: 1625 : (void)ParseByteUnits(random_string_1, default_multiplier);
163 : : }
164 : 1625 : }
|