|
5 | 5 | #include <blockfilter.h>
|
6 | 6 | #include <clientversion.h>
|
7 | 7 | #include <common/url.h>
|
8 |
| -#include <logging.h> |
9 |
| -#include <netaddress.h> |
10 | 8 | #include <netbase.h>
|
11 | 9 | #include <outputtype.h>
|
12 | 10 | #include <rpc/client.h>
|
|
22 | 20 | #include <test/fuzz/util.h>
|
23 | 21 | #include <util/error.h>
|
24 | 22 | #include <util/fees.h>
|
25 |
| -#include <util/message.h> |
26 | 23 | #include <util/settings.h>
|
27 | 24 | #include <util/strencodings.h>
|
28 | 25 | #include <util/string.h>
|
29 | 26 | #include <util/system.h>
|
30 | 27 | #include <util/translation.h>
|
31 |
| -#include <version.h> |
32 | 28 |
|
| 29 | +#include <cassert> |
33 | 30 | #include <cstdint>
|
34 | 31 | #include <cstdlib>
|
| 32 | +#include <ios> |
| 33 | +#include <stdexcept> |
35 | 34 | #include <string>
|
36 | 35 | #include <vector>
|
37 | 36 |
|
38 |
| -namespace { |
39 |
| -bool LegacyParsePrechecks(const std::string& str) |
40 |
| -{ |
41 |
| - if (str.empty()) // No empty string allowed |
42 |
| - return false; |
43 |
| - if (str.size() >= 1 && (IsSpace(str[0]) || IsSpace(str[str.size() - 1]))) // No padding allowed |
44 |
| - return false; |
45 |
| - if (!ContainsNoNUL(str)) // No embedded NUL characters allowed |
46 |
| - return false; |
47 |
| - return true; |
48 |
| -} |
49 |
| - |
50 |
| -bool LegacyParseInt32(const std::string& str, int32_t* out) |
51 |
| -{ |
52 |
| - if (!LegacyParsePrechecks(str)) |
53 |
| - return false; |
54 |
| - char* endp = nullptr; |
55 |
| - errno = 0; // strtol will not set errno if valid |
56 |
| - long int n = strtol(str.c_str(), &endp, 10); |
57 |
| - if (out) *out = (int32_t)n; |
58 |
| - // Note that strtol returns a *long int*, so even if strtol doesn't report an over/underflow |
59 |
| - // we still have to check that the returned value is within the range of an *int32_t*. On 64-bit |
60 |
| - // platforms the size of these types may be different. |
61 |
| - return endp && *endp == 0 && !errno && |
62 |
| - n >= std::numeric_limits<int32_t>::min() && |
63 |
| - n <= std::numeric_limits<int32_t>::max(); |
64 |
| -} |
65 |
| - |
66 |
| -bool LegacyParseInt64(const std::string& str, int64_t* out) |
67 |
| -{ |
68 |
| - if (!LegacyParsePrechecks(str)) |
69 |
| - return false; |
70 |
| - char* endp = nullptr; |
71 |
| - errno = 0; // strtoll will not set errno if valid |
72 |
| - long long int n = strtoll(str.c_str(), &endp, 10); |
73 |
| - if (out) *out = (int64_t)n; |
74 |
| - // Note that strtoll returns a *long long int*, so even if strtol doesn't report an over/underflow |
75 |
| - // we still have to check that the returned value is within the range of an *int64_t*. |
76 |
| - return endp && *endp == 0 && !errno && |
77 |
| - n >= std::numeric_limits<int64_t>::min() && |
78 |
| - n <= std::numeric_limits<int64_t>::max(); |
79 |
| -} |
80 |
| - |
81 |
| -bool LegacyParseUInt32(const std::string& str, uint32_t* out) |
82 |
| -{ |
83 |
| - if (!LegacyParsePrechecks(str)) |
84 |
| - return false; |
85 |
| - if (str.size() >= 1 && str[0] == '-') // Reject negative values, unfortunately strtoul accepts these by default if they fit in the range |
86 |
| - return false; |
87 |
| - char* endp = nullptr; |
88 |
| - errno = 0; // strtoul will not set errno if valid |
89 |
| - unsigned long int n = strtoul(str.c_str(), &endp, 10); |
90 |
| - if (out) *out = (uint32_t)n; |
91 |
| - // Note that strtoul returns a *unsigned long int*, so even if it doesn't report an over/underflow |
92 |
| - // we still have to check that the returned value is within the range of an *uint32_t*. On 64-bit |
93 |
| - // platforms the size of these types may be different. |
94 |
| - return endp && *endp == 0 && !errno && |
95 |
| - n <= std::numeric_limits<uint32_t>::max(); |
96 |
| -} |
97 |
| - |
98 |
| -bool LegacyParseUInt8(const std::string& str, uint8_t* out) |
99 |
| -{ |
100 |
| - uint32_t u32; |
101 |
| - if (!LegacyParseUInt32(str, &u32) || u32 > std::numeric_limits<uint8_t>::max()) { |
102 |
| - return false; |
103 |
| - } |
104 |
| - if (out != nullptr) { |
105 |
| - *out = static_cast<uint8_t>(u32); |
106 |
| - } |
107 |
| - return true; |
108 |
| -} |
109 |
| - |
110 |
| -bool LegacyParseUInt64(const std::string& str, uint64_t* out) |
111 |
| -{ |
112 |
| - if (!LegacyParsePrechecks(str)) |
113 |
| - return false; |
114 |
| - if (str.size() >= 1 && str[0] == '-') // Reject negative values, unfortunately strtoull accepts these by default if they fit in the range |
115 |
| - return false; |
116 |
| - char* endp = nullptr; |
117 |
| - errno = 0; // strtoull will not set errno if valid |
118 |
| - unsigned long long int n = strtoull(str.c_str(), &endp, 10); |
119 |
| - if (out) *out = (uint64_t)n; |
120 |
| - // Note that strtoull returns a *unsigned long long int*, so even if it doesn't report an over/underflow |
121 |
| - // we still have to check that the returned value is within the range of an *uint64_t*. |
122 |
| - return endp && *endp == 0 && !errno && |
123 |
| - n <= std::numeric_limits<uint64_t>::max(); |
124 |
| -} |
125 |
| - |
126 |
| -// For backwards compatibility checking. |
127 |
| -int64_t atoi64_legacy(const std::string& str) |
128 |
| -{ |
129 |
| - return strtoll(str.c_str(), nullptr, 10); |
130 |
| -} |
131 |
| -}; // namespace |
| 37 | +enum class FeeEstimateMode; |
132 | 38 |
|
133 | 39 | FUZZ_TARGET(string)
|
134 | 40 | {
|
@@ -236,61 +142,4 @@ FUZZ_TARGET(string)
|
236 | 142 | const bilingual_str bs2{random_string_2, random_string_1};
|
237 | 143 | (void)(bs1 + bs2);
|
238 | 144 | }
|
239 |
| - { |
240 |
| - int32_t i32; |
241 |
| - int64_t i64; |
242 |
| - uint32_t u32; |
243 |
| - uint64_t u64; |
244 |
| - uint8_t u8; |
245 |
| - const bool ok_i32 = ParseInt32(random_string_1, &i32); |
246 |
| - const bool ok_i64 = ParseInt64(random_string_1, &i64); |
247 |
| - const bool ok_u32 = ParseUInt32(random_string_1, &u32); |
248 |
| - const bool ok_u64 = ParseUInt64(random_string_1, &u64); |
249 |
| - const bool ok_u8 = ParseUInt8(random_string_1, &u8); |
250 |
| - |
251 |
| - int32_t i32_legacy; |
252 |
| - int64_t i64_legacy; |
253 |
| - uint32_t u32_legacy; |
254 |
| - uint64_t u64_legacy; |
255 |
| - uint8_t u8_legacy; |
256 |
| - const bool ok_i32_legacy = LegacyParseInt32(random_string_1, &i32_legacy); |
257 |
| - const bool ok_i64_legacy = LegacyParseInt64(random_string_1, &i64_legacy); |
258 |
| - const bool ok_u32_legacy = LegacyParseUInt32(random_string_1, &u32_legacy); |
259 |
| - const bool ok_u64_legacy = LegacyParseUInt64(random_string_1, &u64_legacy); |
260 |
| - const bool ok_u8_legacy = LegacyParseUInt8(random_string_1, &u8_legacy); |
261 |
| - |
262 |
| - assert(ok_i32 == ok_i32_legacy); |
263 |
| - assert(ok_i64 == ok_i64_legacy); |
264 |
| - assert(ok_u32 == ok_u32_legacy); |
265 |
| - assert(ok_u64 == ok_u64_legacy); |
266 |
| - assert(ok_u8 == ok_u8_legacy); |
267 |
| - |
268 |
| - if (ok_i32) { |
269 |
| - assert(i32 == i32_legacy); |
270 |
| - } |
271 |
| - if (ok_i64) { |
272 |
| - assert(i64 == i64_legacy); |
273 |
| - } |
274 |
| - if (ok_u32) { |
275 |
| - assert(u32 == u32_legacy); |
276 |
| - } |
277 |
| - if (ok_u64) { |
278 |
| - assert(u64 == u64_legacy); |
279 |
| - } |
280 |
| - if (ok_u8) { |
281 |
| - assert(u8 == u8_legacy); |
282 |
| - } |
283 |
| - } |
284 |
| - |
285 |
| - { |
286 |
| - const int locale_independent_atoi_result = LocaleIndependentAtoi<int>(random_string_1); |
287 |
| - const int64_t atoi64_result = atoi64_legacy(random_string_1); |
288 |
| - assert(locale_independent_atoi_result == std::clamp<int64_t>(atoi64_result, std::numeric_limits<int>::min(), std::numeric_limits<int>::max())); |
289 |
| - } |
290 |
| - |
291 |
| - { |
292 |
| - const int64_t atoi64_result = atoi64_legacy(random_string_1); |
293 |
| - const int64_t locale_independent_atoi_result = LocaleIndependentAtoi<int64_t>(random_string_1); |
294 |
| - assert(atoi64_result == locale_independent_atoi_result); |
295 |
| - } |
296 | 145 | }
|
0 commit comments