Add more overflow checks in mmap

This commit is contained in:
Marsman1996
2024-08-28 20:37:36 +08:00
committed by Tate, Hongliang Tian
parent e184094648
commit 9589b332aa
3 changed files with 14 additions and 4 deletions

View File

@ -20,7 +20,10 @@ pub fn sys_madvise(
if start % PAGE_SIZE != 0 {
return_errno_with_message!(Errno::EINVAL, "the start address should be page aligned");
}
if len == 0 || len > usize::MAX - PAGE_SIZE + 1 {
if len > usize::MAX - PAGE_SIZE + 1 {
return_errno_with_message!(Errno::EINVAL, "len align overflow");
}
if len == 0 {
return Ok(SyscallReturn::Return(0));
}