Skip to content

Commit ba2f6cb

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 6bbafa5 commit ba2f6cb

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

0 commit comments

Comments
 (0)