Skip parsing vendor caps with length 0

This commit is contained in:
Jeremy Soller
2022-02-11 09:23:48 -07:00
parent 4a8059302f
commit 5e42b0697e
2 changed files with 9 additions and 3 deletions
+8 -2
View File
@@ -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<R: ConfigReader>(reader: &R, offset: u8) -> Self {
+1 -1
View File
@@ -4,7 +4,7 @@ use super::PciDev;
pub trait ConfigReader {
unsafe fn read_range(&self, offset: u16, len: u16) -> Vec<u8> {
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);