mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-02 09:46:52 -05:00
Merge bitcoin/bitcoin#22322: fuzz: Check banman roundtrip
fa485d06ec
fuzz: Check banman roundtrip (MarcoFalke) Pull request description: ACKs for top commit: practicalswift: cr ACKfa485d06ec
vasild: ACKfa485d06ec
Tree-SHA512: 84e297c0b90ef68d72afd2053bfda2888496c1b180233516a8caaf76d6c03403f1e4ed59f1eb32d799873fc34009634b4ce372244b9d546d04626af41ac4d1d7
This commit is contained in:
commit
246daf1f53
1 changed files with 20 additions and 2 deletions
|
@ -32,6 +32,13 @@ void initialize_banman()
|
|||
static const auto testing_setup = MakeNoLogFileContext<>();
|
||||
}
|
||||
|
||||
static bool operator==(const CBanEntry& lhs, const CBanEntry& rhs)
|
||||
{
|
||||
return lhs.nVersion == rhs.nVersion &&
|
||||
lhs.nCreateTime == rhs.nCreateTime &&
|
||||
lhs.nBanUntil == rhs.nBanUntil;
|
||||
}
|
||||
|
||||
FUZZ_TARGET_INIT(banman, initialize_banman)
|
||||
{
|
||||
// The complexity is O(N^2), where N is the input size, because each call
|
||||
|
@ -43,19 +50,20 @@ FUZZ_TARGET_INIT(banman, initialize_banman)
|
|||
fs::path banlist_file = gArgs.GetDataDirNet() / "fuzzed_banlist";
|
||||
|
||||
const bool start_with_corrupted_banlist{fuzzed_data_provider.ConsumeBool()};
|
||||
bool force_read_and_write_to_err{false};
|
||||
if (start_with_corrupted_banlist) {
|
||||
const std::string sfx{fuzzed_data_provider.ConsumeBool() ? ".dat" : ".json"};
|
||||
assert(WriteBinaryFile(banlist_file.string() + sfx,
|
||||
fuzzed_data_provider.ConsumeRandomLengthString()));
|
||||
} else {
|
||||
const bool force_read_and_write_to_err{fuzzed_data_provider.ConsumeBool()};
|
||||
force_read_and_write_to_err = fuzzed_data_provider.ConsumeBool();
|
||||
if (force_read_and_write_to_err) {
|
||||
banlist_file = fs::path{"path"} / "to" / "inaccessible" / "fuzzed_banlist";
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
BanMan ban_man{banlist_file, nullptr, ConsumeBanTimeOffset(fuzzed_data_provider)};
|
||||
BanMan ban_man{banlist_file, /* client_interface */ nullptr, /* default_ban_time */ ConsumeBanTimeOffset(fuzzed_data_provider)};
|
||||
while (--limit_max_ops >= 0 && fuzzed_data_provider.ConsumeBool()) {
|
||||
CallOneOf(
|
||||
fuzzed_data_provider,
|
||||
|
@ -93,6 +101,16 @@ FUZZ_TARGET_INIT(banman, initialize_banman)
|
|||
ban_man.Discourage(ConsumeNetAddr(fuzzed_data_provider));
|
||||
});
|
||||
}
|
||||
if (!force_read_and_write_to_err) {
|
||||
ban_man.DumpBanlist();
|
||||
SetMockTime(ConsumeTime(fuzzed_data_provider));
|
||||
banmap_t banmap;
|
||||
ban_man.GetBanned(banmap);
|
||||
BanMan ban_man_read{banlist_file, /* client_interface */ nullptr, /* default_ban_time */ 0};
|
||||
banmap_t banmap_read;
|
||||
ban_man_read.GetBanned(banmap_read);
|
||||
assert(banmap == banmap_read);
|
||||
}
|
||||
}
|
||||
fs::remove(banlist_file.string() + ".dat");
|
||||
fs::remove(banlist_file.string() + ".json");
|
||||
|
|
Loading…
Add table
Reference in a new issue