Skip to content

Commit 00864a9

Browse files
committed
Require a non-0 number of non-empty paths when deserializing routes
When we read a `Route` (or a list of `RouteHop`s), we should never have zero paths or zero `RouteHop`s in a path. As such, its fine to simply reject these at deserialization-time. Technically this could lead to something which we can generate not round-trip'ing serialization, but that seems okay here.
1 parent 30b9d9f commit 00864a9

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6790,7 +6790,7 @@ impl Readable for HTLCSource {
67906790
0 => {
67916791
let mut session_priv: crate::util::ser::OptionDeserWrapper<SecretKey> = crate::util::ser::OptionDeserWrapper(None);
67926792
let mut first_hop_htlc_msat: u64 = 0;
6793-
let mut path = Some(Vec::new());
6793+
let mut path: Option<Vec<RouteHop>> = Some(Vec::new());
67946794
let mut payment_id = None;
67956795
let mut payment_secret = None;
67966796
let mut payment_params = None;
@@ -6807,10 +6807,14 @@ impl Readable for HTLCSource {
68076807
// instead.
68086808
payment_id = Some(PaymentId(*session_priv.0.unwrap().as_ref()));
68096809
}
6810+
if path.is_none() || path.as_ref().unwrap().is_empty() {
6811+
return Err(DecodeError::InvalidValue);
6812+
}
6813+
let path = path.unwrap();
68106814
Ok(HTLCSource::OutboundRoute {
68116815
session_priv: session_priv.0.unwrap(),
68126816
first_hop_htlc_msat,
6813-
path: path.unwrap(),
6817+
path,
68146818
payment_id: payment_id.unwrap(),
68156819
payment_secret,
68166820
payment_params,

lightning/src/routing/router.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,13 +313,15 @@ impl Readable for Route {
313313
fn read<R: io::Read>(reader: &mut R) -> Result<Route, DecodeError> {
314314
let _ver = read_ver_prefix!(reader, SERIALIZATION_VERSION);
315315
let path_count: u64 = Readable::read(reader)?;
316+
if path_count == 0 { return Err(DecodeError::InvalidValue); }
316317
let mut paths = Vec::with_capacity(cmp::min(path_count, 128) as usize);
317318
for _ in 0..path_count {
318319
let hop_count: u8 = Readable::read(reader)?;
319320
let mut hops = Vec::with_capacity(hop_count as usize);
320321
for _ in 0..hop_count {
321322
hops.push(Readable::read(reader)?);
322323
}
324+
if hops.is_empty() { return Err(DecodeError::InvalidValue); }
323325
paths.push(hops);
324326
}
325327
let mut payment_params = None;

0 commit comments

Comments
 (0)