@@ -32,6 +32,13 @@ void initialize_banman()
32
32
static const auto testing_setup = MakeNoLogFileContext<>();
33
33
}
34
34
35
+ static bool operator ==(const CBanEntry& lhs, const CBanEntry& rhs)
36
+ {
37
+ return lhs.nVersion == rhs.nVersion &&
38
+ lhs.nCreateTime == rhs.nCreateTime &&
39
+ lhs.nBanUntil == rhs.nBanUntil ;
40
+ }
41
+
35
42
FUZZ_TARGET_INIT (banman, initialize_banman)
36
43
{
37
44
// 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)
43
50
fs::path banlist_file = gArgs .GetDataDirNet () / " fuzzed_banlist" ;
44
51
45
52
const bool start_with_corrupted_banlist{fuzzed_data_provider.ConsumeBool ()};
53
+ bool force_read_and_write_to_err{false };
46
54
if (start_with_corrupted_banlist) {
47
55
const std::string sfx{fuzzed_data_provider.ConsumeBool () ? " .dat" : " .json" };
48
56
assert (WriteBinaryFile (banlist_file.string () + sfx,
49
57
fuzzed_data_provider.ConsumeRandomLengthString ()));
50
58
} else {
51
- const bool force_read_and_write_to_err{ fuzzed_data_provider.ConsumeBool ()} ;
59
+ force_read_and_write_to_err = fuzzed_data_provider.ConsumeBool ();
52
60
if (force_read_and_write_to_err) {
53
61
banlist_file = fs::path{" path" } / " to" / " inaccessible" / " fuzzed_banlist" ;
54
62
}
55
63
}
56
64
57
65
{
58
- BanMan ban_man{banlist_file, nullptr , ConsumeBanTimeOffset (fuzzed_data_provider)};
66
+ BanMan ban_man{banlist_file, /* client_interface */ nullptr , /* default_ban_time */ ConsumeBanTimeOffset (fuzzed_data_provider)};
59
67
while (--limit_max_ops >= 0 && fuzzed_data_provider.ConsumeBool ()) {
60
68
CallOneOf (
61
69
fuzzed_data_provider,
@@ -93,6 +101,16 @@ FUZZ_TARGET_INIT(banman, initialize_banman)
93
101
ban_man.Discourage (ConsumeNetAddr (fuzzed_data_provider));
94
102
});
95
103
}
104
+ if (!force_read_and_write_to_err) {
105
+ ban_man.DumpBanlist ();
106
+ SetMockTime (ConsumeTime (fuzzed_data_provider));
107
+ banmap_t banmap;
108
+ ban_man.GetBanned (banmap);
109
+ BanMan ban_man_read{banlist_file, /* client_interface */ nullptr , /* default_ban_time */ 0 };
110
+ banmap_t banmap_read;
111
+ ban_man_read.GetBanned (banmap_read);
112
+ assert (banmap == banmap_read);
113
+ }
96
114
}
97
115
fs::remove (banlist_file.string () + " .dat" );
98
116
fs::remove (banlist_file.string () + " .json" );
0 commit comments