Skip to content

Commit b1b283d

Browse files
committed
f - check amount_msats against MAX_VALUE_MSAT when parsing
1 parent 1eb211e commit b1b283d

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

lightning/src/offers/offer.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,9 @@ impl TryFrom<OfferTlvStream> for OfferContents {
499499

500500
let amount = match (currency, amount) {
501501
(None, None) => None,
502+
(None, Some(amount_msats)) if amount_msats > MAX_VALUE_MSAT => {
503+
return Err(SemanticError::InvalidAmount);
504+
},
502505
(None, Some(amount_msats)) => Some(Amount::Bitcoin { amount_msats }),
503506
(Some(_), None) => return Err(SemanticError::MissingAmount),
504507
(Some(iso4217_code), Some(amount)) => Some(Amount::Currency { iso4217_code, amount }),

lightning/src/offers/parse.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ pub enum ParseError {
7474
pub enum SemanticError {
7575
/// An amount was expected but was missing.
7676
MissingAmount,
77+
/// The amount exceeded the total bitcoin supply.
78+
InvalidAmount,
7779
/// A required description was not provided.
7880
MissingDescription,
7981
/// A signing pubkey was not provided.

0 commit comments

Comments
 (0)