From f23ded23c26a5326dae249905d298e8c5f51d371 Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Mon, 13 Mar 2017 13:11:26 +0000 Subject: [PATCH] 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.` --- src/packet.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/packet.rs b/src/packet.rs index 25ed442..943e10d 100644 --- a/src/packet.rs +++ b/src/packet.rs @@ -82,7 +82,7 @@ impl convert::TryFrom for Packet { let precision = rdr.read_i8()?; let delay = rdr.read_u32::()?.into(); let dispersion = rdr.read_u32::()?.into(); - let ref_id_raw = rdr.read_u32::().unwrap(); + let ref_id_raw = rdr.read_u32::()?.into(); let ref_id = if stratum.primary() { let source = PrimarySource::try_from(ref_id_raw)?; ReferenceIdentifier::Primary(source)