0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-09 10:43:19 -05:00

[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 <logging.h>
#include <netaddress.h> #include <netaddress.h>
#include <serialize.h> #include <serialize.h>
#include <util/asmap.h>
#include <cmath> #include <cmath>
#include <optional> #include <optional>
@ -1028,7 +1029,7 @@ std::vector<bool> CAddrMan::DecodeAsmap(fs::path path)
bits.push_back((cur_byte >> bit) & 1); bits.push_back((cur_byte >> bit) & 1);
} }
} }
if (!SanityCheckASMap(bits)) { if (!SanityCheckASMap(bits, 128)) {
LogPrintf("Sanity check of asmap file %s failed\n", path); LogPrintf("Sanity check of asmap file %s failed\n", path);
return {}; 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)); 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 #endif // BITCOIN_NETADDRESS_H

View file

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

View file

@ -4,6 +4,7 @@
#include <netaddress.h> #include <netaddress.h>
#include <test/fuzz/fuzz.h> #include <test/fuzz/fuzz.h>
#include <util/asmap.h>
#include <cstdint> #include <cstdint>
#include <vector> #include <vector>
@ -42,7 +43,7 @@ FUZZ_TARGET(asmap)
asmap.push_back((buffer[1 + i] >> j) & 1); 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; const uint8_t* addr_data = buffer.data() + 1 + asmap_size;
CNetAddr net_addr; CNetAddr net_addr;

View file

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