[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.
This commit is contained in:
John Newbery 2021-09-07 13:31:10 +01:00
parent 07a9eccb60
commit bfdf4ef334
6 changed files with 7 additions and 11 deletions

View File

@ -9,6 +9,7 @@
#include <logging.h>
#include <netaddress.h>
#include <serialize.h>
#include <util/asmap.h>
#include <cmath>
#include <optional>
@ -1028,7 +1029,7 @@ std::vector<bool> 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 {};
}

View File

@ -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<bool>& asmap)
{
return SanityCheckASMap(asmap, 128); // For IP address lookups, the input is 128 bits
}

View File

@ -567,6 +567,4 @@ public:
}
};
bool SanityCheckASMap(const std::vector<bool>& asmap);
#endif // BITCOIN_NETADDRESS_H

View File

@ -221,7 +221,7 @@ public:
[[nodiscard]] inline std::vector<bool> ConsumeAsmap(FuzzedDataProvider& fuzzed_data_provider) noexcept
{
std::vector<bool> asmap = ConsumeRandomLengthBitVector(fuzzed_data_provider);
if (!SanityCheckASMap(asmap)) asmap.clear();
if (!SanityCheckASMap(asmap, 128)) asmap.clear();
return asmap;
}

View File

@ -4,6 +4,7 @@
#include <netaddress.h>
#include <test/fuzz/fuzz.h>
#include <util/asmap.h>
#include <cstdint>
#include <vector>
@ -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;

View File

@ -14,6 +14,7 @@
#include <test/fuzz/util.h>
#include <test/util/net.h>
#include <test/util/setup_common.h>
#include <util/asmap.h>
#include <cstdint>
#include <optional>
@ -39,7 +40,7 @@ FUZZ_TARGET_INIT(net, initialize_net)
},
[&] {
const std::vector<bool> asmap = ConsumeRandomLengthBitVector(fuzzed_data_provider);
if (!SanityCheckASMap(asmap)) {
if (!SanityCheckASMap(asmap, 128)) {
return;
}
CNodeStats stats;