Skip to content

Commit ce477a6

Browse files
committed
Introduce DecodeError::UnknownTLV
1 parent 69b7c1b commit ce477a6

File tree

4 files changed

+13
-0
lines changed

4 files changed

+13
-0
lines changed

fuzz/src/router.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
135135
msgs::DecodeError::ShortRead => panic!("We picked the length..."),
136136
msgs::DecodeError::Io(e) => panic!("{:?}", e),
137137
msgs::DecodeError::UnsupportedCompression => return,
138+
msgs::DecodeError::UnknownTLV(_) => return,
138139
}
139140
}
140141
}}

lightning/src/ln/channelmanager.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1765,6 +1765,11 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
17651765
msgs::DecodeError::UnknownRequiredFeature|
17661766
msgs::DecodeError::InvalidValue|
17671767
msgs::DecodeError::ShortRead => 0x4000 | 22, // invalid_onion_payload
1768+
msgs::DecodeError::UnknownTLV(tlv_type) => {
1769+
let tlv_type = BigSize(tlv_type);
1770+
let mut v = Vec::with_capacity(tlv_type.serialized_length());
1771+
return_err!("Unable to decode our hop data", 0x4000 | 22, if let Ok(_) = tlv_type.write(&mut v) { &v[..] } else { &[0;0] });
1772+
},
17681773
_ => 0x2000 | 2, // Should never happen
17691774
};
17701775
return_err!("Unable to decode our hop data", error_code, &[0;0]);

lightning/src/ln/msgs.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ pub enum DecodeError {
6868
io::ErrorKind),
6969
/// The message included zlib-compressed values, which we don't support.
7070
UnsupportedCompression,
71+
/// The message included a TLV with an unknown type.
72+
UnknownTLV(u64),
7173
}
7274

7375
/// An init message to be sent or received from a peer
@@ -965,6 +967,7 @@ impl fmt::Display for DecodeError {
965967
DecodeError::BadLengthDescriptor => f.write_str("A length descriptor in the packet didn't describe the later data correctly"),
966968
DecodeError::Io(ref e) => e.fmt(f),
967969
DecodeError::UnsupportedCompression => f.write_str("We don't support receiving messages with zlib-compressed fields"),
970+
DecodeError::UnknownTLV(tlv_type) => f.write_fmt(format_args!( "Unknown TLV type encountered: {}", tlv_type)),
968971
}
969972
}
970973
}

lightning/src/ln/peer_handler.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,10 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, L: Deref, CMH: Deref> P
908908
msgs::DecodeError::UnsupportedCompression => {
909909
log_trace!(self.logger, "We don't support zlib-compressed message fields, ignoring message");
910910
continue;
911+
},
912+
msgs::DecodeError::UnknownTLV(tlv_type) => {
913+
log_debug!(self.logger, "Got an unknown TLV type while deserializing message: {}", tlv_type);
914+
return Err(PeerHandleError { no_connection_possible: false });
911915
}
912916
}
913917
}

0 commit comments

Comments
 (0)