mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-25 10:43:19 -03:00
fuzz: Speed up banman fuzz target
This commit is contained in:
parent
ea8b2e8e12
commit
fae0f836be
1 changed files with 5 additions and 3 deletions
|
@ -32,13 +32,17 @@ void initialize_banman()
|
|||
|
||||
FUZZ_TARGET_INIT(banman, initialize_banman)
|
||||
{
|
||||
// The complexity is O(N^2), where N is the input size, because each call
|
||||
// might call DumpBanlist (or other methods that are at least linear
|
||||
// complexity of the input size).
|
||||
int limit_max_ops{300};
|
||||
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
|
||||
SetMockTime(ConsumeTime(fuzzed_data_provider));
|
||||
const fs::path banlist_file = GetDataDir() / "fuzzed_banlist.dat";
|
||||
fs::remove(banlist_file);
|
||||
{
|
||||
BanMan ban_man{banlist_file, nullptr, ConsumeBanTimeOffset(fuzzed_data_provider)};
|
||||
while (fuzzed_data_provider.ConsumeBool()) {
|
||||
while (--limit_max_ops >= 0 && fuzzed_data_provider.ConsumeBool()) {
|
||||
CallOneOf(
|
||||
fuzzed_data_provider,
|
||||
[&] {
|
||||
|
@ -52,7 +56,6 @@ FUZZ_TARGET_INIT(banman, initialize_banman)
|
|||
[&] {
|
||||
ban_man.ClearBanned();
|
||||
},
|
||||
[] {},
|
||||
[&] {
|
||||
ban_man.IsBanned(ConsumeNetAddr(fuzzed_data_provider));
|
||||
},
|
||||
|
@ -72,7 +75,6 @@ FUZZ_TARGET_INIT(banman, initialize_banman)
|
|||
[&] {
|
||||
ban_man.DumpBanlist();
|
||||
},
|
||||
[] {},
|
||||
[&] {
|
||||
ban_man.Discourage(ConsumeNetAddr(fuzzed_data_provider));
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue