From 858c064ca29898c89cf17940170374d3143155e6 Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Mon, 28 Jul 2025 14:31:52 +0200 Subject: [PATCH] graph/db: fix potential nil pointer derefs Here, we fix two bugs that could lead to a nil pointer dereference. Both are caused by refering to policies that may be nil at the call-site. --- graph/db/sql_store.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/graph/db/sql_store.go b/graph/db/sql_store.go index 081154f0f..c90efac28 100644 --- a/graph/db/sql_store.go +++ b/graph/db/sql_store.go @@ -1188,7 +1188,7 @@ func (s *SQLStore) ForEachNodeCached(ctx context.Context, var cachedInPolicy *models.CachedEdgePolicy if inPolicy != nil { cachedInPolicy = models.NewCachedPolicy( - p2, + inPolicy, ) cachedInPolicy.ToNodePubKey = toNodeCallback @@ -1197,11 +1197,13 @@ func (s *SQLStore) ForEachNodeCached(ctx context.Context, } var inboundFee lnwire.Fee - outPolicy.InboundFee.WhenSome( - func(fee lnwire.Fee) { - inboundFee = fee - }, - ) + if outPolicy != nil { + outPolicy.InboundFee.WhenSome( + func(fee lnwire.Fee) { + inboundFee = fee + }, + ) + } directedChannel := &DirectedChannel{ ChannelID: e.ChannelID, @@ -1209,7 +1211,7 @@ func (s *SQLStore) ForEachNodeCached(ctx context.Context, e.NodeKey1Bytes, OtherNode: e.NodeKey2Bytes, Capacity: e.Capacity, - OutPolicySet: p1 != nil, + OutPolicySet: outPolicy != nil, InPolicy: cachedInPolicy, InboundFee: inboundFee, }