Fix amount overflow in Offer parsing and building
[rust-lightning] / lightning / src / offers / offer.rs
index b0819f9e9204f70c707c16312b70668741bdde85..405e2e278d8073eac345a801f88906422989f173 100644 (file)
@@ -431,7 +431,8 @@ impl OfferContents {
                };
 
                if !self.expects_quantity() || quantity.is_some() {
-                       let expected_amount_msats = offer_amount_msats * quantity.unwrap_or(1);
+                       let expected_amount_msats = offer_amount_msats.checked_mul(quantity.unwrap_or(1))
+                               .ok_or(SemanticError::InvalidAmount)?;
                        let amount_msats = amount_msats.unwrap_or(expected_amount_msats);
 
                        if amount_msats < expected_amount_msats {