diff options
author | Vasil Dimov <vd@FreeBSD.org> | 2021-01-14 09:33:04 +0100 |
---|---|---|
committer | Vasil Dimov <vd@FreeBSD.org> | 2021-06-21 14:39:44 +0200 |
commit | d197977ae2076903ed12ab7616a7f93e88be02e1 (patch) | |
tree | f52c91c3abad65cffa13a8334c37da415c708c70 /src/test/fuzz | |
parent | 6a67366fdc3e1d383fe7cbfa209d7e85f0d96638 (diff) | |
download | bitcoin-d197977ae2076903ed12ab7616a7f93e88be02e1.tar.xz |
banman: save the banlist in a JSON format on disk
Save the banlist in `banlist.json` instead of `banlist.dat`.
This makes it possible to store Tor v3 entries in the banlist on disk
(and any other addresses that cannot be serialized in addrv1 format).
Only read `banlist.dat` if it exists and `banlist.json` does not
exist (first start after an upgrade).
Supersedes https://github.com/bitcoin/bitcoin/pull/20904
Resolves https://github.com/bitcoin/bitcoin/issues/19748
Diffstat (limited to 'src/test/fuzz')
-rw-r--r-- | src/test/fuzz/banman.cpp | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/src/test/fuzz/banman.cpp b/src/test/fuzz/banman.cpp index 759a70a857..cca41e79ae 100644 --- a/src/test/fuzz/banman.cpp +++ b/src/test/fuzz/banman.cpp @@ -9,8 +9,10 @@ #include <test/fuzz/fuzz.h> #include <test/fuzz/util.h> #include <test/util/setup_common.h> +#include <util/readwritefile.h> #include <util/system.h> +#include <cassert> #include <cstdint> #include <limits> #include <string> @@ -38,8 +40,20 @@ FUZZ_TARGET_INIT(banman, initialize_banman) int limit_max_ops{300}; FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()}; SetMockTime(ConsumeTime(fuzzed_data_provider)); - const fs::path banlist_file = gArgs.GetDataDirNet() / "fuzzed_banlist.dat"; - fs::remove(banlist_file); + fs::path banlist_file = gArgs.GetDataDirNet() / "fuzzed_banlist"; + + const bool start_with_corrupted_banlist{fuzzed_data_provider.ConsumeBool()}; + 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()}; + 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)}; while (--limit_max_ops >= 0 && fuzzed_data_provider.ConsumeBool()) { @@ -80,5 +94,6 @@ FUZZ_TARGET_INIT(banman, initialize_banman) }); } } - fs::remove(banlist_file); + fs::remove(banlist_file.string() + ".dat"); + fs::remove(banlist_file.string() + ".json"); } |