From: Valentine Wallace Date: Tue, 30 Apr 2024 17:01:03 +0000 (-0400) Subject: Fix overflow in invoice amount setter. X-Git-Tag: v0.0.123-rc1~1^2~1^2 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=0ea58d0713e1b20d46c44a3a078c7da5f299d3ca;p=rust-lightning Fix overflow in invoice amount setter. --- diff --git a/lightning-invoice/src/lib.rs b/lightning-invoice/src/lib.rs index 920d44b15..fb34240be 100644 --- a/lightning-invoice/src/lib.rs +++ b/lightning-invoice/src/lib.rs @@ -577,7 +577,13 @@ impl Self { - let amount = amount_msat * 10; // Invoices are denominated in "pico BTC" + let amount = match amount_msat.checked_mul(10) { // Invoices are denominated in "pico BTC" + Some(amt) => amt, + None => { + self.error = Some(CreationError::InvalidAmount); + return self + } + }; let biggest_possible_si_prefix = SiPrefix::values_desc() .iter() .find(|prefix| amount % prefix.multiplier() == 0)