You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ag...@apache.org on 2021/11/01 10:08:09 UTC

[incubator-nuttx] branch master updated: ftruncate: sanity check for parameter:length

This is an automated email from the ASF dual-hosted git repository.

aguettouche pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new e5f8aca  ftruncate: sanity check for parameter:length
e5f8aca is described below

commit e5f8acab97a4a9400a4f8d492d79c48bd1823245
Author: Jiuzhu Dong <do...@xiaomi.com>
AuthorDate: Sun Oct 31 12:29:59 2021 +0800

    ftruncate: sanity check for parameter:length
    
    Signed-off-by: Jiuzhu Dong <do...@xiaomi.com>
---
 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 17b89ed..4ecd06c 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. */