mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2025-02-21 19:02:30 +00:00
devices: cmos: Increase robustness of CMOS device
Check sizes of data reads/writes to avoid panics. Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
parent
43f0dd6d25
commit
ccda1a004e
@ -51,13 +51,14 @@ impl Cmos {
|
||||
impl BusDevice for Cmos {
|
||||
fn write(&mut self, _base: u64, offset: u64, data: &[u8]) -> Option<Arc<Barrier>> {
|
||||
if data.len() != 1 {
|
||||
warn!("Invalid write size on CMOS device: {}", data.len());
|
||||
return None;
|
||||
}
|
||||
|
||||
match offset {
|
||||
INDEX_OFFSET => self.index = data[0] & INDEX_MASK,
|
||||
DATA_OFFSET => self.data[self.index as usize] = data[0],
|
||||
o => panic!("bad write offset on CMOS device: {}", o),
|
||||
o => warn!("bad write offset on CMOS device: {}", o),
|
||||
};
|
||||
None
|
||||
}
|
||||
@ -69,6 +70,7 @@ impl BusDevice for Cmos {
|
||||
}
|
||||
|
||||
if data.len() != 1 {
|
||||
warn!("Invalid read size on CMOS device: {}", data.len());
|
||||
return;
|
||||
}
|
||||
|
||||
@ -126,7 +128,10 @@ impl BusDevice for Cmos {
|
||||
}
|
||||
}
|
||||
}
|
||||
o => panic!("bad read offset on CMOS device: {}", o),
|
||||
o => {
|
||||
warn!("bad read offset on CMOS device: {}", o);
|
||||
0
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user