summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2019-02-04 12:38:55 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2019-02-06 08:31:13 +0100
commit20eea939a6fef5a02d55e83b997cd8c86607d83f (patch)
tree3bd5f141c0b79af338cd678fd00d2174c703fadb
parent97e7c77a70ba37619d1883d224f9e218b1755b20 (diff)
downloadbarebox-20eea939a6fef5a02d55e83b997cd8c86607d83f.tar.gz
barebox-20eea939a6fef5a02d55e83b997cd8c86607d83f.tar.xz
fs: do not call truncate for FILE_SIZE_STREAM sized files
open_and_lseek() increases the file size when the file is opened in write mode and scrolled past the files end. This fails badly on /dev/mem because loff_t which we use for the file size is signed variable, which is used as an unsigned variable in /dev/mem. To catch this case do not try to truncate FILE_SIZE_STREAM sized files. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--fs/fs.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/fs/fs.c b/fs/fs.c
index c5b17e158a..1374286e62 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -213,6 +213,9 @@ int ftruncate(int fd, loff_t length)
f = &files[fd];
+ if (f->size == FILE_SIZE_STREAM)
+ return 0;
+
fsdrv = f->fsdev->driver;
ret = fsdrv->truncate(&f->fsdev->dev, f, length);