Skip to content

Commit 886be97

Browse files
committed
Ignore incorrectly-serialized banlist.dat entries
1 parent 883cea7 commit 886be97

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

src/banman.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ void BanMan::SweepBanned()
184184
while (it != m_banned.end()) {
185185
CSubNet sub_net = (*it).first;
186186
CBanEntry ban_entry = (*it).second;
187-
if (now > ban_entry.nBanUntil) {
187+
if (!sub_net.IsValid() || now > ban_entry.nBanUntil) {
188188
m_banned.erase(it++);
189189
m_is_dirty = true;
190190
notify_ui = true;

src/netaddress.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,6 +1109,17 @@ bool CSubNet::IsValid() const
11091109
return valid;
11101110
}
11111111

1112+
bool CSubNet::SanityCheck() const
1113+
{
1114+
if (!(network.IsIPv4() || network.IsIPv6())) return false;
1115+
1116+
for (size_t x = 0; x < network.m_addr.size(); ++x) {
1117+
if (network.m_addr[x] & ~netmask[x]) return false;
1118+
}
1119+
1120+
return true;
1121+
}
1122+
11121123
bool operator==(const CSubNet& a, const CSubNet& b)
11131124
{
11141125
return a.valid == b.valid && a.network == b.network && !memcmp(a.netmask, b.netmask, 16);

src/netaddress.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,8 @@ class CSubNet
451451
/// Is this value valid? (only used to signal parse errors)
452452
bool valid;
453453

454+
bool SanityCheck() const;
455+
454456
public:
455457
CSubNet();
456458
CSubNet(const CNetAddr& addr, uint8_t mask);
@@ -482,6 +484,8 @@ class CSubNet
482484
READWRITE(obj.netmask);
483485
}
484486
READWRITE(obj.valid);
487+
// Mark invalid if the result doesn't pass sanity checking.
488+
SER_READ(obj, if (obj.valid) obj.valid = obj.SanityCheck());
485489
}
486490
};
487491

0 commit comments

Comments
 (0)