Skip to content

Commit f23ded2

Browse files
author
Daniel Lockyer
committed
Fix panic caused by a malformed input
Converting from bytes to a Packet struct can fail and the unwrap will cause a panic. All other lines use `?.into()` - which fixes the issue. An example of a malformed input would be: `0x23,0xc,0xfd,0x0,0x0,0x0,0x0,0x0,0x0,0x2a,0x0,0x0,0x0,0x0` Found using `cargo-fuzz.`
1 parent b175b57 commit f23ded2

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/packet.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ impl<T: ReadBytesExt> convert::TryFrom<T> for Packet {
8282
let precision = rdr.read_i8()?;
8383
let delay = rdr.read_u32::<NetworkEndian>()?.into();
8484
let dispersion = rdr.read_u32::<NetworkEndian>()?.into();
85-
let ref_id_raw = rdr.read_u32::<NetworkEndian>().unwrap();
85+
let ref_id_raw = rdr.read_u32::<NetworkEndian>()?.into();
8686
let ref_id = if stratum.primary() {
8787
let source = PrimarySource::try_from(ref_id_raw)?;
8888
ReferenceIdentifier::Primary(source)

0 commit comments

Comments
 (0)