Skip to content

Commit ee0a406

Browse files
committed
Refuse to deserialize OnionHopDatas with values > 21 million
We should probably do this for all values (and define a newtype for msat values), but this will do for now.
1 parent 33ac6c8 commit ee0a406

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

lightning/src/ln/msgs.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ use util::ser::{Readable, Writeable, Writer, FixedLengthReader, HighZeroBytesDro
3333

3434
use ln::channelmanager::{PaymentPreimage, PaymentHash};
3535

36+
/// 21 million * 10^8 * 1000
37+
pub(crate) const MAX_VALUE_MSAT: u64 = 21_000_000_0000_0000_000;
38+
3639
/// An error in decoding a message or struct.
3740
#[derive(Debug)]
3841
pub enum DecodeError {
@@ -1054,6 +1057,11 @@ impl Readable for OnionHopData {
10541057
short_channel_id,
10551058
}
10561059
} else {
1060+
if let &Some(ref data) = &payment_data {
1061+
if data.total_msat > MAX_VALUE_MSAT {
1062+
return Err(DecodeError::InvalidValue);
1063+
}
1064+
}
10571065
OnionHopDataFormat::FinalNode {
10581066
payment_data
10591067
}
@@ -1065,6 +1073,9 @@ impl Readable for OnionHopData {
10651073
};
10661074
let amt: u64 = Readable::read(r)?;
10671075
let cltv_value: u32 = Readable::read(r)?;
1076+
if amt > MAX_VALUE_MSAT {
1077+
return Err(DecodeError::InvalidValue);
1078+
}
10681079
r.read_exact(&mut [0; 12])?;
10691080
(format, amt, cltv_value)
10701081
};

0 commit comments

Comments
 (0)