Skip to content

Commit 78ab54f

Browse files
authored
Merge pull request #3039 from valentinewallace/2024-04-invoice-amt-msats-overflow
Fix overflow in invoice amount setter.
2 parents b8d4ac1 + 0ea58d0 commit 78ab54f

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

lightning-invoice/src/lib.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,13 @@ impl<D: tb::Bool, H: tb::Bool, T: tb::Bool, C: tb::Bool, S: tb::Bool, M: tb::Boo
577577

578578
/// Sets the amount in millisatoshis. The optimal SI prefix is chosen automatically.
579579
pub fn amount_milli_satoshis(mut self, amount_msat: u64) -> Self {
580-
let amount = amount_msat * 10; // Invoices are denominated in "pico BTC"
580+
let amount = match amount_msat.checked_mul(10) { // Invoices are denominated in "pico BTC"
581+
Some(amt) => amt,
582+
None => {
583+
self.error = Some(CreationError::InvalidAmount);
584+
return self
585+
}
586+
};
581587
let biggest_possible_si_prefix = SiPrefix::values_desc()
582588
.iter()
583589
.find(|prefix| amount % prefix.multiplier() == 0)

0 commit comments

Comments
 (0)