From 10bc7aa3df2c88c2d5528cabf8827251bdfc6f77 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Wed, 29 Aug 2018 15:36:58 -0400 Subject: [PATCH] Ignore invalid lnd msgs by matching DecodeError instead of a macro --- src/ln/peer_handler.rs | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/ln/peer_handler.rs b/src/ln/peer_handler.rs index 9315f5690..7af4c0e29 100644 --- a/src/ln/peer_handler.rs +++ b/src/ln/peer_handler.rs @@ -331,21 +331,19 @@ impl PeerManager { ($thing: expr) => { match $thing { Ok(x) => x, - Err(_e) => { - //TODO: Handle e? - return Err(PeerHandleError{ no_connection_possible: false }); - } - }; - } - } - - macro_rules! try_ignore_potential_decodeerror { - ($thing: expr) => { - match $thing { - Ok(x) => x, - Err(_e) => { - log_debug!(self, "Error decoding message, ignoring due to lnd spec incompatibility. See https://github.com/lightningnetwork/lnd/issues/1407"); - continue; + Err(e) => { + match e { + msgs::DecodeError::UnknownRealmByte => return Err(PeerHandleError{ no_connection_possible: false }), + msgs::DecodeError::BadPublicKey => return Err(PeerHandleError{ no_connection_possible: false }), + msgs::DecodeError::BadSignature => return Err(PeerHandleError{ no_connection_possible: false }), + msgs::DecodeError::BadText => return Err(PeerHandleError{ no_connection_possible: false }), + msgs::DecodeError::ShortRead => return Err(PeerHandleError{ no_connection_possible: false }), + msgs::DecodeError::ExtraAddressesPerType => { + log_debug!(self, "Error decoding message, ignoring due to lnd spec incompatibility. See https://github.com/lightningnetwork/lnd/issues/1407"); + continue; + }, + msgs::DecodeError::BadLengthDescriptor => return Err(PeerHandleError{ no_connection_possible: false }), + } } }; } @@ -576,7 +574,7 @@ impl PeerManager { } }, 257 => { - let msg = try_ignore_potential_decodeerror!(msgs::NodeAnnouncement::decode(&msg_data[2..])); + let msg = try_potential_decodeerror!(msgs::NodeAnnouncement::decode(&msg_data[2..])); try_potential_handleerror!(self.message_handler.route_handler.handle_node_announcement(&msg)); }, 258 => { -- 2.39.5