Skip parsing vendor caps with length 0
This commit is contained in:
+8
-2
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user