Skip to content

Commit c91589d

Browse files
author
MarcoFalke
committed
Merge bitcoin/bitcoin#22005: fuzz: Speed up banman fuzz target
fae0f83 fuzz: Speed up banman fuzz target (MarcoFalke) Pull request description: Hopefully fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=34463 ACKs for top commit: practicalswift: cr ACK fae0f83: patch looks correct and touches only `src/test/fuzz/banman.cpp` Tree-SHA512: edbad168c607d09a5f4a29639f2d0b852605dd61403334356ad35a1eac667b6ce3922b1b316fdf37a991195fbc24e947df9e37359231663f8a364e5889e28417
2 parents 5cf92c3 + fae0f83 commit c91589d

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/test/fuzz/banman.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,17 @@ void initialize_banman()
3232

3333
FUZZ_TARGET_INIT(banman, initialize_banman)
3434
{
35+
// The complexity is O(N^2), where N is the input size, because each call
36+
// might call DumpBanlist (or other methods that are at least linear
37+
// complexity of the input size).
38+
int limit_max_ops{300};
3539
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
3640
SetMockTime(ConsumeTime(fuzzed_data_provider));
3741
const fs::path banlist_file = gArgs.GetDataDirNet() / "fuzzed_banlist.dat";
3842
fs::remove(banlist_file);
3943
{
4044
BanMan ban_man{banlist_file, nullptr, ConsumeBanTimeOffset(fuzzed_data_provider)};
41-
while (fuzzed_data_provider.ConsumeBool()) {
45+
while (--limit_max_ops >= 0 && fuzzed_data_provider.ConsumeBool()) {
4246
CallOneOf(
4347
fuzzed_data_provider,
4448
[&] {
@@ -52,7 +56,6 @@ FUZZ_TARGET_INIT(banman, initialize_banman)
5256
[&] {
5357
ban_man.ClearBanned();
5458
},
55-
[] {},
5659
[&] {
5760
ban_man.IsBanned(ConsumeNetAddr(fuzzed_data_provider));
5861
},
@@ -72,7 +75,6 @@ FUZZ_TARGET_INIT(banman, initialize_banman)
7275
[&] {
7376
ban_man.DumpBanlist();
7477
},
75-
[] {},
7678
[&] {
7779
ban_man.Discourage(ConsumeNetAddr(fuzzed_data_provider));
7880
});

0 commit comments

Comments
 (0)