From 905727b6844075bce1054f60ba6beb4437b6ea37 Mon Sep 17 00:00:00 2001 From: Ajay Bhargav Date: Sun, 17 Feb 2019 17:09:58 +0530 Subject: [PATCH] Fix: length more than LFS_FILE_MAX should return error To make lfs_file_truncate inline with ftruncate function, when -ve or size more than maximum file size is passed to function it should return invalid parameter error. In LFS case LFS_ERR_INVAL. Signed-off-by: Ajay Bhargav --- lfs.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lfs.c b/lfs.c index 25c88c6..99ab36e 100644 --- a/lfs.c +++ b/lfs.c @@ -2864,6 +2864,10 @@ int lfs_file_truncate(lfs_t *lfs, lfs_file_t *file, lfs_off_t size) { return LFS_ERR_BADF; } + if (size > LFS_FILE_MAX) { + return LFS_ERR_INVAL; + } + lfs_off_t oldsize = lfs_file_size(lfs, file); if (size < oldsize) { // need to flush since directly changing metadata