Skip to content

Commit 6c99579

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 20c2522 commit 6c99579

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};
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 {
@@ -1095,6 +1098,11 @@ impl<R: Read> Readable<R> for OnionHopData {
10951098
short_channel_id,
10961099
}
10971100
} else {
1101+
if let &Some(ref data) = &payment_data {
1102+
if data.total_msat > MAX_VALUE_MSAT {
1103+
return Err(DecodeError::InvalidValue);
1104+
}
1105+
}
10981106
OnionHopDataFormat::FinalNode {
10991107
payment_data
11001108
}
@@ -1106,6 +1114,9 @@ impl<R: Read> Readable<R> for OnionHopData {
11061114
};
11071115
let amt: u64 = Readable::read(r)?;
11081116
let cltv_value: u32 = Readable::read(r)?;
1117+
if amt > MAX_VALUE_MSAT {
1118+
return Err(DecodeError::InvalidValue);
1119+
}
11091120
r.read_exact(&mut [0; 12])?;
11101121
(format, amt, cltv_value)
11111122
};

0 commit comments

Comments
 (0)