From c7465bdb3e138def94f77848671567b24991345b Mon Sep 17 00:00:00 2001 From: Jeffrey Czyz Date: Thu, 18 Jan 2024 15:34:19 -0600 Subject: [PATCH 1/2] Fix panic when peer is mid-handshake Peer::their_node_id is set to Some during the handshake process. However, df3ab2ee2753e7f9ec02ddf1c8a51db77c50e35d accesses the field unconditionally, causing a panic. This may be triggered if a gossip message is received mid-handshake from another peer or if the user calls broadcast_node_announcement during this time. The latter tends to be executed on a timer. Ensure that Peer::their_node_id is only accessed once the handshake is complete. --- lightning/src/ln/peer_handler.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lightning/src/ln/peer_handler.rs b/lightning/src/ln/peer_handler.rs index 6d46558b188..100446f0540 100644 --- a/lightning/src/ln/peer_handler.rs +++ b/lightning/src/ln/peer_handler.rs @@ -1835,13 +1835,13 @@ impl Date: Mon, 22 Jan 2024 16:26:54 -0600 Subject: [PATCH 2/2] Remove unnecessary unwraps --- lightning/src/ln/peer_handler.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lightning/src/ln/peer_handler.rs b/lightning/src/ln/peer_handler.rs index 100446f0540..c3a50fd2490 100644 --- a/lightning/src/ln/peer_handler.rs +++ b/lightning/src/ln/peer_handler.rs @@ -1272,7 +1272,7 @@ impl(&self, peer: &mut Peer, message: &M) { - let logger = WithContext::from(&self.logger, Some(peer.their_node_id.unwrap().0), None); + let logger = WithContext::from(&self.logger, peer.their_node_id.map(|p| p.0), None); if is_gossip_msg(message.type_id()) { log_gossip!(logger, "Enqueueing message {:?} to {}", message, log_pubkey!(peer.their_node_id.unwrap().0)); } else { @@ -1377,7 +1377,7 @@ impl { - let logger = WithContext::from(&self.logger, Some(peer.their_node_id.unwrap().0), None); + let logger = WithContext::from(&self.logger, peer.their_node_id.map(|p| p.0), None); match self.node_id_to_descriptor.lock().unwrap().entry(peer.their_node_id.unwrap().0) { hash_map::Entry::Occupied(e) => { log_trace!(logger, "Got second connection with {}, closing", log_pubkey!(peer.their_node_id.unwrap().0)); @@ -1457,7 +1457,7 @@ impl x, Err(e) => { @@ -1841,7 +1841,7 @@ impl