From 19550f9f7f63d6fe2dab191f2044f4e4f5d59df6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Nohlg=C3=A5rd?= Date: Sat, 23 Apr 2016 10:03:09 +0200 Subject: [PATCH] core/cfs: Disallow seeking past the end of a file if it is not writable --- core/cfs/cfs-coffee.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/core/cfs/cfs-coffee.c b/core/cfs/cfs-coffee.c index 79eb18d94..37b1a707e 100644 --- a/core/cfs/cfs-coffee.c +++ b/core/cfs/cfs-coffee.c @@ -1055,7 +1055,12 @@ cfs_seek(int fd, cfs_offset_t offset, int whence) } if(fdp->file->end < new_offset) { - fdp->file->end = new_offset; + if(FD_WRITABLE(fd)) { + fdp->file->end = new_offset; + } else { + /* Disallow seeking past the end of the file for read only FDs */ + return (cfs_offset_t)-1; + } } return fdp->offset = new_offset;