]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Refuse to deserialize OnionHopDatas with values > 21 million
authorMatt Corallo <git@bluematt.me>
Thu, 2 Jan 2020 02:13:48 +0000 (21:13 -0500)
committerMatt Corallo <git@bluematt.me>
Tue, 14 Apr 2020 23:54:17 +0000 (19:54 -0400)
We should probably do this for all values (and define a newtype
for msat values), but this will do for now.

lightning/src/ln/msgs.rs

index 294dbb965e781aebdfa90bcb00ca4e2fff081755..e915f04152092f77388f20af1ad5d1d495cc245a 100644 (file)
@@ -33,6 +33,9 @@ use util::ser::{Readable, Writeable, Writer, FixedLengthReader, HighZeroBytesDro
 
 use ln::channelmanager::{PaymentPreimage, PaymentHash};
 
+/// 21 million * 10^8 * 1000
+pub(crate) const MAX_VALUE_MSAT: u64 = 21_000_000_0000_0000_000;
+
 /// An error in decoding a message or struct.
 #[derive(Debug)]
 pub enum DecodeError {
@@ -1053,6 +1056,11 @@ impl Readable for OnionHopData {
                                        short_channel_id,
                                }
                        } else {
+                               if let &Some(ref data) = &payment_data {
+                                       if data.total_msat > MAX_VALUE_MSAT {
+                                               return Err(DecodeError::InvalidValue);
+                                       }
+                               }
                                OnionHopDataFormat::FinalNode {
                                        payment_data
                                }
@@ -1068,6 +1076,9 @@ impl Readable for OnionHopData {
                        (format, amt, cltv_value)
                };
 
+               if amt > MAX_VALUE_MSAT {
+                       return Err(DecodeError::InvalidValue);
+               }
                Ok(OnionHopData {
                        format,
                        amt_to_forward: amt,