From ca3585a483ca5f6fc4cc54fd1530f89d13e5b7b0 Mon Sep 17 00:00:00 2001 From: John Newbery Date: Tue, 14 Jul 2020 10:24:43 +0100 Subject: [net/net processing] check banman pointer before dereferencing Although we currently don't do this, it should be possible to create a CConnman or PeerLogicValidation without a Banman instance. Therefore always check that banman exists before dereferencing the pointer. Also add comments to the m_banman members of CConnman and PeerLogicValidation to document that these may be nullptr. --- src/net.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/net.cpp') diff --git a/src/net.cpp b/src/net.cpp index 244b0094d6..cf5757d6c0 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -1013,7 +1013,7 @@ void CConnman::AcceptConnection(const ListenSocket& hListenSocket) { SetSocketNoDelay(hSocket); // Don't accept connections from banned peers. - bool banned = m_banman->IsBanned(addr); + bool banned = m_banman && m_banman->IsBanned(addr); if (!NetPermissions::HasFlag(permissionFlags, NetPermissionFlags::PF_NOBAN) && banned) { LogPrint(BCLog::NET, "connection from %s dropped (banned)\n", addr.ToString()); @@ -1022,7 +1022,7 @@ void CConnman::AcceptConnection(const ListenSocket& hListenSocket) { } // Only accept connections from discouraged peers if our inbound slots aren't (almost) full. - bool discouraged = m_banman->IsDiscouraged(addr); + bool discouraged = m_banman && m_banman->IsDiscouraged(addr); if (!NetPermissions::HasFlag(permissionFlags, NetPermissionFlags::PF_NOBAN) && nInbound + 1 >= nMaxInbound && discouraged) { LogPrint(BCLog::NET, "connection from %s dropped (discouraged)\n", addr.ToString()); -- cgit v1.2.3