From 1cd87d6f9768ce6eda6b8cc17bab22b5734d59f5 Mon Sep 17 00:00:00 2001 From: Peter Bee Date: Thu, 21 Jan 2021 11:36:52 +0800 Subject: [PATCH] fs/mmap: add fd validation to correct errno MIRTOS-111 Errors EBADF correctly. This is only a quick fix, and a lot needs to be done with mmap(). Change-Id: Ica88360972447fbdd7c6af3bf76d8eeba4747db2 Signed-off-by: Peter Bee --- fs/mmap/fs_rammap.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/fs/mmap/fs_rammap.c b/fs/mmap/fs_rammap.c index 23e6ceb330d..d81832e2956 100644 --- a/fs/mmap/fs_rammap.c +++ b/fs/mmap/fs_rammap.c @@ -140,6 +140,12 @@ FAR void *rammap(int fd, size_t length, off_t offset) /* Allocate a region of memory of the specified size */ + if ((unsigned int)fd >= CONFIG_NFILE_DESCRIPTORS) + { + errcode = EBADF; + goto errout; + } + alloc = (FAR uint8_t *)kumm_malloc(sizeof(struct fs_rammap_s) + length); if (!alloc) {