Skip to content

Commit fae0f83

Browse files
author
MarcoFalke
committed
fuzz: Speed up banman fuzz target
1 parent ea8b2e8 commit fae0f83

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 = GetDataDir() / "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)