fs/mmap: add sanity check

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
This commit is contained in:
dongjiuzhu1 2023-05-10 11:28:33 +08:00 committed by Xiang Xiao
parent e4739ab575
commit 88161bfca5
2 changed files with 14 additions and 0 deletions

View File

@ -74,6 +74,13 @@ static int file_mmap_(FAR struct file *filep, FAR void *start,
*/
#ifdef CONFIG_DEBUG_FEATURES
/* A flags with MAP_PRIVATE and MAP_SHARED is invalid. */
if ((flags & MAP_PRIVATE) && (flags & MAP_SHARED))
{
return -EINVAL;
}
/* Fixed mappings and protections are not currently supported. These
* options could be supported in the KERNEL build with an MMU, but that
* logic is not in place.

View File

@ -69,6 +69,13 @@ static int file_munmap_(FAR void *start, size_t length, bool kernel)
mm_map_unlock();
}
/* If entry don't find, the start and length is invalid. */
if (entry == NULL)
{
return -EINVAL;
}
return ret;
}