]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Fix overflow in invoice amount setter.
authorValentine Wallace <vwallace@protonmail.com>
Tue, 30 Apr 2024 17:01:03 +0000 (13:01 -0400)
committerValentine Wallace <vwallace@protonmail.com>
Mon, 6 May 2024 15:20:04 +0000 (11:20 -0400)
lightning-invoice/src/lib.rs

index 920d44b1561dbf12f8afdc1e3e5105eb8a5aefef..fb34240bee1b32ee397f9acce1de769db65bf9a7 100644 (file)
@@ -577,7 +577,13 @@ impl<D: tb::Bool, H: tb::Bool, T: tb::Bool, C: tb::Bool, S: tb::Bool, M: tb::Boo
 
        /// Sets the amount in millisatoshis. The optimal SI prefix is chosen automatically.
        pub fn amount_milli_satoshis(mut self, amount_msat: u64) -> 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)