diff options
author | MarcoFalke <falke.marco@gmail.com> | 2021-06-25 10:07:49 +0200 |
---|---|---|
committer | MarcoFalke <falke.marco@gmail.com> | 2021-06-25 10:07:58 +0200 |
commit | 246daf1f537d4b7a39774b22db86ed1931b7819b (patch) | |
tree | 001bd8c74d69912acd5610aa24f2f481d9620857 | |
parent | b2f5c38333fd2ec03fd1299a1bce507b25753f45 (diff) | |
parent | fa485d06ec10acd9a791f8d29689e1e82591fb70 (diff) |
Merge bitcoin/bitcoin#22322: fuzz: Check banman roundtrip
fa485d06ec10acd9a791f8d29689e1e82591fb70 fuzz: Check banman roundtrip (MarcoFalke)
Pull request description:
ACKs for top commit:
practicalswift:
cr ACK fa485d06ec10acd9a791f8d29689e1e82591fb70
vasild:
ACK fa485d06ec10acd9a791f8d29689e1e82591fb70
Tree-SHA512: 84e297c0b90ef68d72afd2053bfda2888496c1b180233516a8caaf76d6c03403f1e4ed59f1eb32d799873fc34009634b4ce372244b9d546d04626af41ac4d1d7
-rw-r--r-- | src/test/fuzz/banman.cpp | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/src/test/fuzz/banman.cpp b/src/test/fuzz/banman.cpp index cca41e79ae..182aabc79b 100644 --- a/src/test/fuzz/banman.cpp +++ b/src/test/fuzz/banman.cpp @@ -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"); |