From c4e43dbaa219548c2d6bfb4064e498a4ffac8ac0 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Tue, 15 Aug 2017 17:49:10 -0700 Subject: [PATCH] server: avoid nil pointer deference within OutboundPeerConnected --- server.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/server.go b/server.go index 2b4ba6b3..b6b8d804 100644 --- a/server.go +++ b/server.go @@ -960,7 +960,9 @@ func (s *server) OutboundPeerConnected(connReq *connmgr.ConnReq, conn net.Conn) // entry for this peer from the map. if connReqs, ok := s.persistentConnReqs[pubStr]; ok { for _, pConnReq := range connReqs { - if pConnReq.ID() != connReq.ID() { + if connReq != nil && + pConnReq.ID() != connReq.ID() { + s.connMgr.Remove(pConnReq.ID()) } } @@ -977,7 +979,11 @@ func (s *server) OutboundPeerConnected(connReq *connmgr.ConnReq, conn net.Conn) srvrLog.Warnf("Established outbound connection to "+ "peer %x, but already connected, dropping conn", nodePub.SerializeCompressed()) - s.connMgr.Remove(connReq.ID()) + + if connReq != nil { + s.connMgr.Remove(connReq.ID()) + } + conn.Close() return }