Skip to content

Commit 3dc0bb9

Browse files
committed
Merge bitcoin/bitcoin#24298: fuzz: Avoid unsigned integer overflow in FormatParagraph
fa2f7d0 fuzz: Avoid unsigned integer overflow in FormatParagraph (MarcoFalke) Pull request description: `FormatParagraph` is only ever called with compile time constant arguments, so I don't see the need for fuzzing it. Though, keep it for now, but avoid the unsigned integer overflow with this patch. ACKs for top commit: laanwj: Code review ACK fa2f7d0 Tree-SHA512: 01fc64a9ef73c183921ca1b0cd8db9514c0a242e3acf215a3393f383ae129e01625ebb16eaf9cb86370eda62d0145c3dcf8f62e40edf5958abc1f777c5687280
2 parents 8c0f02c + fa2f7d0 commit 3dc0bb9

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

src/test/fuzz/string.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ FUZZ_TARGET(string)
145145
(void)CopyrightHolders(random_string_1);
146146
FeeEstimateMode fee_estimate_mode;
147147
(void)FeeModeFromString(random_string_1, fee_estimate_mode);
148-
(void)FormatParagraph(random_string_1, fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, 1000), fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, 1000));
148+
const auto width{fuzzed_data_provider.ConsumeIntegralInRange<size_t>(1, 1000)};
149+
(void)FormatParagraph(random_string_1, width, fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, width));
149150
(void)FormatSubVersion(random_string_1, fuzzed_data_provider.ConsumeIntegral<int>(), random_string_vector);
150151
(void)GetDescriptorChecksum(random_string_1);
151152
(void)HelpExampleCli(random_string_1, random_string_2);

src/util/strencodings.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ bool ParseUInt64(const std::string& str, uint64_t* out)
328328

329329
std::string FormatParagraph(const std::string& in, size_t width, size_t indent)
330330
{
331+
assert(width >= indent);
331332
std::stringstream out;
332333
size_t ptr = 0;
333334
size_t indented = 0;

0 commit comments

Comments
 (0)