Require a non-0 number of non-empty paths when deserializing routes
[rust-lightning] / lightning / src / routing / router.rs
index b456e15a2d13cdce9b6090889e1e886ae17a997c..0a3c540607ae7ab27e8f3ad3a2411e320da43d86 100644 (file)
@@ -313,6 +313,7 @@ impl Readable for Route {
        fn read<R: io::Read>(reader: &mut R) -> Result<Route, DecodeError> {
                let _ver = read_ver_prefix!(reader, SERIALIZATION_VERSION);
                let path_count: u64 = Readable::read(reader)?;
+               if path_count == 0 { return Err(DecodeError::InvalidValue); }
                let mut paths = Vec::with_capacity(cmp::min(path_count, 128) as usize);
                for _ in 0..path_count {
                        let hop_count: u8 = Readable::read(reader)?;
@@ -320,6 +321,7 @@ impl Readable for Route {
                        for _ in 0..hop_count {
                                hops.push(Readable::read(reader)?);
                        }
+                       if hops.is_empty() { return Err(DecodeError::InvalidValue); }
                        paths.push(hops);
                }
                let mut payment_params = None;