From 3f6afa51b9c5f0975835f71235e7add584a026a3 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Thu, 2 Feb 2017 16:49:52 -0800 Subject: [PATCH] rpcserver: fix potential panic when opening channel to peer_id MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit fixes a potential panic that could arise when one was attempting to open a channel with the target peer identified by it’s peerID and an error occurred. In this case, the nodepubKey pointer would be nil, resulting in a panic when attempting to propagate the error. This commit fixes this bug by using a nil byte slice for the node’s serialized pubkey in the case that the node was identified according to ti’s peer ID. --- rpcserver.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/rpcserver.go b/rpcserver.go index 6c27d195..3749a98c 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -258,8 +258,9 @@ func (r *rpcServer) OpenChannel(in *lnrpc.OpenChannelRequest, } var ( - nodepubKey *btcec.PublicKey - err error + nodepubKey *btcec.PublicKey + nodepubKeyBytes []byte + err error ) // If the node key is set, the we'll parse the raw bytes into a pubkey @@ -270,6 +271,7 @@ func (r *rpcServer) OpenChannel(in *lnrpc.OpenChannelRequest, if err != nil { return err } + nodepubKeyBytes = nodepubKey.SerializeCompressed() } // Instruct the server to trigger the necessary events to attempt to @@ -285,8 +287,7 @@ out: case err := <-errChan: rpcsLog.Errorf("unable to open channel to "+ "identityPub(%x) nor peerID(%v): %v", - nodepubKey.SerializeCompressed(), - in.TargetPeerId, err) + nodepubKeyBytes, in.TargetPeerId, err) return err case fundingUpdate := <-updateChan: rpcsLog.Tracef("[openchannel] sending update: %v", @@ -426,6 +427,8 @@ func (r *rpcServer) CloseChannel(in *lnrpc.CloseChannelRequest, // As the first part of the force closure, we first fetch the // channel from the database, then execute a direct force // closure broadcasting our current commitment transaction. + // TODO(roasbeef): d/c peer if connected? + // * otherwise safety no guaranteed channel, err := r.fetchActiveChannel(*chanPoint) if err != nil { return err