From a4e26eaa4a70f7d2eb768d122f20650ff9d71ecb Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Thu, 13 Apr 2017 14:44:53 -0700 Subject: [PATCH] routing: fix bug in path finding when len(rootPath) > len(shortestPath) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit fixes a bug within the k-shortest paths routine which could result in a daemon panic when traversing a graph with particular characteristics. Before referencing the path to create a sub-slice, we we’re properly asserting that the length of the path was at least as long as the current rootPath in question. We fix this by simply ensuring the length of the slice is adequate before proceeding with the operation. --- routing/pathfind.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/routing/pathfind.go b/routing/pathfind.go index 44c0cb99..96985a10 100644 --- a/routing/pathfind.go +++ b/routing/pathfind.go @@ -494,10 +494,10 @@ func findPaths(graph *channeldb.ChannelGraph, source *channeldb.LightningNode, // next round. for _, path := range shortestPaths { // If our current rootPath is a prefix of this - // shortest path, then we'll remove the ege + // shortest path, then we'll remove the edge // directly _after_ our spur node from the // graph so we don't repeat paths. - if isSamePath(rootPath, path[:i+1]) { + if len(path) > i+1 && isSamePath(rootPath, path[:i+1]) { ignoredEdges[path[i+1].ChannelID] = struct{}{} } }