From 4d37508417153c1263ee22acbd5614c37e927c3c Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Mon, 4 Jun 2018 16:40:37 -0700 Subject: [PATCH] rpc: ensure we don't attempt to create a routing hint with a nil edge In this commit, we fix an existing panic bug related to the recently added routing hints feature. If it's the case that the remote node didn't send us their edge, then when we go to compare the public keys to see if they match, we may attempt to deref an nil pointer. In order to fix this, we'll instead check the edgeInfo, which is guaranteed to also exist if the channel was found in the database. As a defensive step, before we go to actually aces the struct, we'll check that's it's non-nil and proceed if it is nil. --- rpcserver.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/rpcserver.go b/rpcserver.go index 7aa1a2f9e..da8404917 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -2321,7 +2321,7 @@ func (r *rpcServer) AddInvoice(ctx context.Context, // Fetch the policies for each end of the channel. chanID := channel.ShortChanID().ToUint64() - _, p1, p2, err := graph.FetchChannelEdgesByID(chanID) + info, p1, p2, err := graph.FetchChannelEdgesByID(chanID) if err != nil { rpcsLog.Errorf("Unable to fetch the routing "+ "policies for the edges of the channel "+ @@ -2332,14 +2332,20 @@ func (r *rpcServer) AddInvoice(ctx context.Context, // Now, we'll need to determine which is the correct // policy for HTLCs being sent from the remote node. var remotePolicy *channeldb.ChannelEdgePolicy - remotePub := channel.IdentityPub.SerializeCompressed() - if bytes.Equal(remotePub, p1.Node.PubKeyBytes[:]) { + if bytes.Equal(remotePub, info.NodeKey1Bytes[:]) { remotePolicy = p1 } else { remotePolicy = p2 } + // If for some reason we don't yet have the edge for + // the remote party, then we'll just skip adding this + // channel as a routing hint. + if remotePolicy == nil { + continue + } + // Finally, create the routing hint for this channel and // add it to our list of route hints. hint := routing.HopHint{