aboutsummaryrefslogtreecommitdiff
path: root/src/netaddress.cpp
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@protonmail.com>2020-10-15 11:22:52 +0200
committerWladimir J. van der Laan <laanwj@protonmail.com>2020-10-15 11:44:36 +0200
commite3b474c548668b653a4868c7be67e09f58e2382f (patch)
treea187f685df792d48ad026437913e5ff024c046c9 /src/netaddress.cpp
parent3956165903cf2fce3acd61ed6f2625f769ac7e2f (diff)
parent886be97af5d4aba338b23a7b20b8560be8156231 (diff)
downloadbitcoin-e3b474c548668b653a4868c7be67e09f58e2382f.tar.xz
Merge #20140: Restore compatibility with old CSubNet serialization
886be97af5d4aba338b23a7b20b8560be8156231 Ignore incorrectly-serialized banlist.dat entries (Pieter Wuille) 883cea7dea3cedc9b45b6191f7d4e7be2d9a11ca Restore compatibility with old CSubNet serialization (Pieter Wuille) Pull request description: #19628 changed CSubNet for IPv4 netmasks, using the first 4 bytes of `netmask` rather than the last 4 to store the actual mask. Unfortunately, CSubNet objects are serialized on disk in banlist.dat, breaking compatibility with existing banlists (and bringing them into an inconsistent state where entries reported in `listbanned` cannot be removed). Fix this by reverting to the old format (just for serialization). Also add a sanity check to the deserializer so that nonsensical banlist.dat entries are ignored (which would otherwise be possible if someone added IPv4 entries after #19628 but without this PR). Reported by Greg Maxwell. ACKs for top commit: laanwj: Code review ACK 886be97af5d4aba338b23a7b20b8560be8156231 vasild: ACK 886be97af Tree-SHA512: d3fb91e8ecd933406e527187974f22770374ee2e12a233e7870363f52ecda471fb0b7bae72420e8ff6b6b1594e3037a5115984c023dbadf38f86aeaffcd681e7
Diffstat (limited to 'src/netaddress.cpp')
-rw-r--r--src/netaddress.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/netaddress.cpp b/src/netaddress.cpp
index 6695ec3700..c0193fa2e9 100644
--- a/src/netaddress.cpp
+++ b/src/netaddress.cpp
@@ -1109,6 +1109,17 @@ bool CSubNet::IsValid() const
return valid;
}
+bool CSubNet::SanityCheck() const
+{
+ if (!(network.IsIPv4() || network.IsIPv6())) return false;
+
+ for (size_t x = 0; x < network.m_addr.size(); ++x) {
+ if (network.m_addr[x] & ~netmask[x]) return false;
+ }
+
+ return true;
+}
+
bool operator==(const CSubNet& a, const CSubNet& b)
{
return a.valid == b.valid && a.network == b.network && !memcmp(a.netmask, b.netmask, 16);