Skip to content

Commit

Permalink
Fix panic caused by a malformed input
Browse files Browse the repository at this point in the history
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.`
  • Loading branch information
Daniel Lockyer committed Mar 13, 2017
1 parent b175b57 commit f23ded2
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl<T: ReadBytesExt> convert::TryFrom<T> for Packet {
let precision = rdr.read_i8()?;
let delay = rdr.read_u32::<NetworkEndian>()?.into();
let dispersion = rdr.read_u32::<NetworkEndian>()?.into();
let ref_id_raw = rdr.read_u32::<NetworkEndian>().unwrap();
let ref_id_raw = rdr.read_u32::<NetworkEndian>()?.into();
let ref_id = if stratum.primary() {
let source = PrimarySource::try_from(ref_id_raw)?;
ReferenceIdentifier::Primary(source)
Expand Down

0 comments on commit f23ded2

Please sign in to comment.