From 0ea58d0713e1b20d46c44a3a078c7da5f299d3ca Mon Sep 17 00:00:00 2001 From: Valentine Wallace Date: Tue, 30 Apr 2024 13:01:03 -0400 Subject: [PATCH] Fix overflow in invoice amount setter. --- lightning-invoice/src/lib.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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) -- 2.39.5