Fix panic in Cursor::new by invalid Vaddr range

This commit is contained in:
Marsman1996
2024-09-11 16:23:21 +08:00
committed by Tate, Hongliang Tian
parent 8bfbdf6642
commit f01772ca85

View File

@ -141,7 +141,7 @@ where
/// Note that this function does not ensure exclusive access to the claimed
/// virtual address range. The accesses using this cursor may block or fail.
pub fn new(pt: &'a PageTable<M, E, C>, va: &Range<Vaddr>) -> Result<Self, PageTableError> {
if !M::covers(va) {
if !M::covers(va) || va.is_empty() {
return Err(PageTableError::InvalidVaddrRange(va.start, va.end));
}
if va.start % C::BASE_PAGE_SIZE != 0 || va.end % C::BASE_PAGE_SIZE != 0 {