Skip to content

Commit 30a2049

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 53ea492 commit 30a2049

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 {
@@ -1053,6 +1056,11 @@ impl Readable for OnionHopData {
10531056
short_channel_id,
10541057
}
10551058
} else {
1059+
if let &Some(ref data) = &payment_data {
1060+
if data.total_msat > MAX_VALUE_MSAT {
1061+
return Err(DecodeError::InvalidValue);
1062+
}
1063+
}
10561064
OnionHopDataFormat::FinalNode {
10571065
payment_data
10581066
}
@@ -1068,6 +1076,9 @@ impl Readable for OnionHopData {
10681076
(format, amt, cltv_value)
10691077
};
10701078

1079+
if amt > MAX_VALUE_MSAT {
1080+
return Err(DecodeError::InvalidValue);
1081+
}
10711082
Ok(OnionHopData {
10721083
format,
10731084
amt_to_forward: amt,

0 commit comments

Comments
 (0)