From e8bc0c92ad61cf607bd544124c69fd2b6a801776 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Wed, 26 Jun 2024 14:16:50 +0000 Subject: [PATCH] Handle feerates of `u32::MAX` without overflowing Though we generally shouldn't be seeing these, and the `get_dust_buffer_feerate` implementation will still return `u32::MAX` in spite of the overflow, we should handle the overflow to avoid panic when `debug_assertions` are enabled. Found by the `full_stack_target` fuzzer --- lightning/src/ln/channel.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs index f5c47260f..5415eb2fc 100644 --- a/lightning/src/ln/channel.rs +++ b/lightning/src/ln/channel.rs @@ -2768,7 +2768,7 @@ impl ChannelContext where SP::Target: SignerProvider { feerate_per_kw = cmp::max(feerate_per_kw, feerate); } let feerate_plus_quarter = feerate_per_kw.checked_mul(1250).map(|v| v / 1000); - cmp::max(feerate_per_kw + 2530, feerate_plus_quarter.unwrap_or(u32::max_value())) + cmp::max(feerate_per_kw.saturating_add(2530), feerate_plus_quarter.unwrap_or(u32::MAX)) } /// Get forwarding information for the counterparty. -- 2.39.5