From bfdf4ef334a16ef6108a658bf4f8514754128c18 Mon Sep 17 00:00:00 2001 From: John Newbery Date: Tue, 7 Sep 2021 13:31:10 +0100 Subject: [PATCH] [asmap] Remove SanityCheckASMap() from netaddress SanityCheckASMap(asmap, bits) simply calls through to SanityCheckASMap(asmap) in util/asmap. Update all callers to simply call that function. --- src/addrman.cpp | 3 ++- src/netaddress.cpp | 5 ----- src/netaddress.h | 2 -- src/test/fuzz/addrman.cpp | 2 +- src/test/fuzz/asmap.cpp | 3 ++- src/test/fuzz/net.cpp | 3 ++- 6 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/addrman.cpp b/src/addrman.cpp index 986a1a5d4b..fd0d3dc6fa 100644 --- a/src/addrman.cpp +++ b/src/addrman.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -1028,7 +1029,7 @@ std::vector CAddrMan::DecodeAsmap(fs::path path) bits.push_back((cur_byte >> bit) & 1); } } - if (!SanityCheckASMap(bits)) { + if (!SanityCheckASMap(bits, 128)) { LogPrintf("Sanity check of asmap file %s failed\n", path); return {}; } diff --git a/src/netaddress.cpp b/src/netaddress.cpp index e7b3377475..b2f4945e3b 100644 --- a/src/netaddress.cpp +++ b/src/netaddress.cpp @@ -1242,8 +1242,3 @@ bool operator<(const CSubNet& a, const CSubNet& b) { return (a.network < b.network || (a.network == b.network && memcmp(a.netmask, b.netmask, 16) < 0)); } - -bool SanityCheckASMap(const std::vector& asmap) -{ - return SanityCheckASMap(asmap, 128); // For IP address lookups, the input is 128 bits -} diff --git a/src/netaddress.h b/src/netaddress.h index eb35ed3fac..cfb2edcd34 100644 --- a/src/netaddress.h +++ b/src/netaddress.h @@ -567,6 +567,4 @@ public: } }; -bool SanityCheckASMap(const std::vector& asmap); - #endif // BITCOIN_NETADDRESS_H diff --git a/src/test/fuzz/addrman.cpp b/src/test/fuzz/addrman.cpp index e95126a80f..fdbfb3b93b 100644 --- a/src/test/fuzz/addrman.cpp +++ b/src/test/fuzz/addrman.cpp @@ -221,7 +221,7 @@ public: [[nodiscard]] inline std::vector ConsumeAsmap(FuzzedDataProvider& fuzzed_data_provider) noexcept { std::vector asmap = ConsumeRandomLengthBitVector(fuzzed_data_provider); - if (!SanityCheckASMap(asmap)) asmap.clear(); + if (!SanityCheckASMap(asmap, 128)) asmap.clear(); return asmap; } diff --git a/src/test/fuzz/asmap.cpp b/src/test/fuzz/asmap.cpp index 4c5bc0cbf2..d402f8632c 100644 --- a/src/test/fuzz/asmap.cpp +++ b/src/test/fuzz/asmap.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include @@ -42,7 +43,7 @@ FUZZ_TARGET(asmap) asmap.push_back((buffer[1 + i] >> j) & 1); } } - if (!SanityCheckASMap(asmap)) return; + if (!SanityCheckASMap(asmap, 128)) return; const uint8_t* addr_data = buffer.data() + 1 + asmap_size; CNetAddr net_addr; diff --git a/src/test/fuzz/net.cpp b/src/test/fuzz/net.cpp index ff0259c182..0929376045 100644 --- a/src/test/fuzz/net.cpp +++ b/src/test/fuzz/net.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -39,7 +40,7 @@ FUZZ_TARGET_INIT(net, initialize_net) }, [&] { const std::vector asmap = ConsumeRandomLengthBitVector(fuzzed_data_provider); - if (!SanityCheckASMap(asmap)) { + if (!SanityCheckASMap(asmap, 128)) { return; } CNodeStats stats;