From: Matt Corallo Date: Wed, 26 Jun 2024 14:16:50 +0000 (+0000) Subject: Handle feerates of `u32::MAX` without overflowing X-Git-Tag: v0.0.124-beta~67^2 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=e8bc0c92ad61cf607bd544124c69fd2b6a801776;p=rust-lightning 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 --- 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.