Skip to content

Commit e67d8c6

Browse files
committed
Don't unwrap() get_channel_update result in HTLC router
This fixes a bug in 78232f2 found by fuzzer - if the channel isn't yet fully established we will call get_channel_update(), get an Err result, and then unwrap() it. If this actually happens it means someone on the network is making up short_channel_ids and trying to route over them, but that shouldn't result in us crashing
1 parent b4fc5b6 commit e67d8c6

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/ln/channelmanager.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1942,10 +1942,20 @@ impl ChannelManager {
19421942
// but if we've sent a shutdown and they haven't acknowledged it yet, we just
19431943
// want to reject the new HTLC and fail it backwards instead of forwarding.
19441944
if let PendingHTLCStatus::Forward(PendingForwardHTLCInfo { incoming_shared_secret, .. }) = pending_forward_info {
1945+
let chan_update = self.get_channel_update(chan);
19451946
pending_forward_info = PendingHTLCStatus::Fail(HTLCFailureMsg::Relay(msgs::UpdateFailHTLC {
19461947
channel_id: msg.channel_id,
19471948
htlc_id: msg.htlc_id,
1948-
reason: ChannelManager::build_first_hop_failure_packet(&incoming_shared_secret, 0x1000|20, &self.get_channel_update(chan).unwrap().encode_with_len()[..]),
1949+
reason: if let Ok(update) = chan_update {
1950+
ChannelManager::build_first_hop_failure_packet(&incoming_shared_secret, 0x1000|20, &update.encode_with_len()[..])
1951+
} else {
1952+
// This can only happen if the channel isn't in the fully-funded
1953+
// state yet, implying our counterparty is trying to route payments
1954+
// over the channel back to themselves (cause no one else should
1955+
// know the short_id is a lightning channel yet). We should have no
1956+
// problem just calling this unknown_next_peer
1957+
ChannelManager::build_first_hop_failure_packet(&incoming_shared_secret, 0x4000|10, &[])
1958+
},
19491959
}));
19501960
}
19511961
}

0 commit comments

Comments
 (0)