@@ -31,6 +31,13 @@ void initialize_banman()
31
31
static const auto testing_setup = MakeNoLogFileContext<>();
32
32
}
33
33
34
+ static bool operator ==(const CBanEntry& lhs, const CBanEntry& rhs)
35
+ {
36
+ return lhs.nVersion == rhs.nVersion &&
37
+ lhs.nCreateTime == rhs.nCreateTime &&
38
+ lhs.nBanUntil == rhs.nBanUntil ;
39
+ }
40
+
34
41
FUZZ_TARGET_INIT (banman, initialize_banman)
35
42
{
36
43
// The complexity is O(N^2), where N is the input size, because each call
@@ -42,18 +49,19 @@ FUZZ_TARGET_INIT(banman, initialize_banman)
42
49
fs::path banlist_file = GetDataDir () / " fuzzed_banlist" ;
43
50
44
51
const bool start_with_corrupted_banlist{fuzzed_data_provider.ConsumeBool ()};
52
+ bool force_read_and_write_to_err{false };
45
53
if (start_with_corrupted_banlist) {
46
54
assert (WriteBinaryFile (banlist_file.string () + " .json" ,
47
55
fuzzed_data_provider.ConsumeRandomLengthString ()));
48
56
} else {
49
- const bool force_read_and_write_to_err{ fuzzed_data_provider.ConsumeBool ()} ;
57
+ force_read_and_write_to_err = fuzzed_data_provider.ConsumeBool ();
50
58
if (force_read_and_write_to_err) {
51
59
banlist_file = fs::path{" path" } / " to" / " inaccessible" / " fuzzed_banlist" ;
52
60
}
53
61
}
54
62
55
63
{
56
- BanMan ban_man{banlist_file, nullptr , ConsumeBanTimeOffset (fuzzed_data_provider)};
64
+ BanMan ban_man{banlist_file, /* client_interface */ nullptr , /* default_ban_time */ ConsumeBanTimeOffset (fuzzed_data_provider)};
57
65
while (--limit_max_ops >= 0 && fuzzed_data_provider.ConsumeBool ()) {
58
66
CallOneOf (
59
67
fuzzed_data_provider,
@@ -91,6 +99,16 @@ FUZZ_TARGET_INIT(banman, initialize_banman)
91
99
ban_man.Discourage (ConsumeNetAddr (fuzzed_data_provider));
92
100
});
93
101
}
102
+ if (!force_read_and_write_to_err) {
103
+ ban_man.DumpBanlist ();
104
+ SetMockTime (ConsumeTime (fuzzed_data_provider));
105
+ banmap_t banmap;
106
+ ban_man.GetBanned (banmap);
107
+ BanMan ban_man_read{banlist_file, /* client_interface */ nullptr , /* default_ban_time */ 0 };
108
+ banmap_t banmap_read;
109
+ ban_man_read.GetBanned (banmap_read);
110
+ assert (banmap == banmap_read);
111
+ }
94
112
}
95
113
fs::remove (banlist_file.string () + " .json" );
96
114
}
0 commit comments