Skip to content

Commit a0a079f

Browse files
gmaxwellfurszy
authored andcommitted
Return early in IsBanned.
I am not aware of any reason that we'd try to stop a ban-list timing side-channel and the prior code wouldn't be enough if we were.
1 parent 7772138 commit a0a079f

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

src/net.cpp

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -453,34 +453,30 @@ void CConnman::ClearBanned()
453453

454454
bool CConnman::IsBanned(CNetAddr ip)
455455
{
456-
bool fResult = false;
456+
LOCK(cs_setBanned);
457+
for (banmap_t::iterator it = setBanned.begin(); it != setBanned.end(); it++)
457458
{
458-
LOCK(cs_setBanned);
459-
for (banmap_t::iterator it = setBanned.begin(); it != setBanned.end(); it++)
460-
{
461-
CSubNet subNet = (*it).first;
462-
CBanEntry banEntry = (*it).second;
459+
CSubNet subNet = (*it).first;
460+
CBanEntry banEntry = (*it).second;
463461

464-
if(subNet.Match(ip) && GetTime() < banEntry.nBanUntil)
465-
fResult = true;
462+
if (subNet.Match(ip) && GetTime() < banEntry.nBanUntil) {
463+
return true;
466464
}
467465
}
468-
return fResult;
466+
return false;
469467
}
470468

471469
bool CConnman::IsBanned(CSubNet subnet)
472470
{
473-
bool fResult = false;
474-
{
475-
LOCK(cs_setBanned);
476-
banmap_t::iterator i = setBanned.find(subnet);
477-
if (i != setBanned.end()) {
478-
CBanEntry banEntry = (*i).second;
479-
if (GetTime() < banEntry.nBanUntil)
480-
fResult = true;
471+
LOCK(cs_setBanned);
472+
banmap_t::iterator i = setBanned.find(subnet);
473+
if (i != setBanned.end()) {
474+
CBanEntry banEntry = (*i).second;
475+
if (GetTime() < banEntry.nBanUntil) {
476+
return true;
481477
}
482478
}
483-
return fResult;
479+
return false;
484480
}
485481

486482
void CConnman::Ban(const CNetAddr& addr, const BanReason &banReason, int64_t bantimeoffset, bool sinceUnixEpoch)

0 commit comments

Comments
 (0)