diff --git a/pcid/src/pci/cap.rs b/pcid/src/pci/cap.rs index cef9108e35..43003fb9a5 100644 --- a/pcid/src/pci/cap.rs +++ b/pcid/src/pci/cap.rs @@ -186,9 +186,15 @@ impl Capability { log::info!("Vendor specific next: {}", reader.read_u8((offset+1).into())); let length = reader.read_u8(u16::from(offset+2)); log::info!("Vendor specific cap len: {}", length); - let mut raw_data = reader.read_range(offset.into(), length.into()); + let data = if length > 0 { + let mut raw_data = reader.read_range(offset.into(), length.into()); + raw_data.drain(3..).collect() + } else { + log::warn!("Vendor specific capability is invalid"); + Vec::new() + }; Self::Vendor(VendorSpecificCapability { - data: raw_data.drain(3..).collect(), + data }) } unsafe fn parse_pcie(reader: &R, offset: u8) -> Self { diff --git a/pcid/src/pci/func.rs b/pcid/src/pci/func.rs index 1b278bd057..fbdda1cfc6 100644 --- a/pcid/src/pci/func.rs +++ b/pcid/src/pci/func.rs @@ -4,7 +4,7 @@ use super::PciDev; pub trait ConfigReader { unsafe fn read_range(&self, offset: u16, len: u16) -> Vec { - assert!(len > 3 && len % 4 == 0); + assert!(len > 3 && len % 4 == 0, "invalid range length: {}", len); let mut ret = Vec::with_capacity(len as usize); let results = (offset..offset + len).step_by(4).fold(Vec::new(), |mut acc, offset| { let val = self.read_u32(offset);