From e5f8acab97a4a9400a4f8d492d79c48bd1823245 Mon Sep 17 00:00:00 2001 From: Jiuzhu Dong Date: Sun, 31 Oct 2021 12:29:59 +0800 Subject: [PATCH] ftruncate: sanity check for parameter:length Signed-off-by: Jiuzhu Dong --- fs/vfs/fs_truncate.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/fs/vfs/fs_truncate.c b/fs/vfs/fs_truncate.c index 17b89edab65..4ecd06c13d4 100644 --- a/fs/vfs/fs_truncate.c +++ b/fs/vfs/fs_truncate.c @@ -155,7 +155,12 @@ int file_truncate(FAR struct file *filep, off_t length) int ftruncate(int fd, off_t length) { FAR struct file *filep; - int ret; + int ret = -EINVAL; + + if (length < 0) + { + goto errout; + } /* Get the file structure corresponding to the file descriptor. */