File tree Expand file tree Collapse file tree 3 files changed +16
-1
lines changed
Expand file tree Collapse file tree 3 files changed +16
-1
lines changed Original file line number Diff line number Diff 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 ;
Original file line number Diff line number Diff 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+
11121123bool operator ==(const CSubNet& a, const CSubNet& b)
11131124{
11141125 return a.valid == b.valid && a.network == b.network && !memcmp (a.netmask , b.netmask , 16 );
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments