hrev52547 adds 1 changeset to branch 'master'
old head: 9cc0f06a015202f58ae669f0bf7653e66161d7e2
new head: 8c053e955ea87e1cc2c1292237ff7fcf836cf495
overview:
https://git.haiku-os.org/haiku/log/?qt=range&q=8c053e955ea8+%5E9cc0f06a0152
----------------------------------------------------------------------------
8c053e955ea8: vfs: fail write_stat() on file descriptors opened read-only.
Change-Id: I20d586c606c47df6625cc9272f153250a5a621d6
Reviewed-on: https://review.haiku-os.org/706
Reviewed-by: waddlesplash <waddlesplash@xxxxxxxxx>
[ Jérôme Duval <jerome.duval@xxxxxxxxx> ]
----------------------------------------------------------------------------
Revision: hrev52547
Commit: 8c053e955ea87e1cc2c1292237ff7fcf836cf495
URL: https://git.haiku-os.org/haiku/commit/?id=8c053e955ea8
Author: Jérôme Duval <jerome.duval@xxxxxxxxx>
Date: Sat Nov 17 23:46:57 2018 UTC
Committer: waddlesplash <waddlesplash@xxxxxxxxx>
Commit-Date: Sun Nov 18 00:04:26 2018 UTC
----------------------------------------------------------------------------
2 files changed, 18 insertions(+)
src/system/kernel/fs/vfs.cpp | 3 +++
src/tests/system/libroot/posix/truncate.cpp | 15 +++++++++++++++
----------------------------------------------------------------------------
diff --git a/src/system/kernel/fs/vfs.cpp b/src/system/kernel/fs/vfs.cpp
index c06660f875..e5de2b366f 100644
--- a/src/system/kernel/fs/vfs.cpp
+++ b/src/system/kernel/fs/vfs.cpp
@@ -6562,6 +6562,9 @@ common_write_stat(struct file_descriptor* descriptor,
const struct stat* stat,
FUNCTION(("common_write_stat(vnode = %p, stat = %p, statMask = %d)\n",
vnode, stat, statMask));
+ if ((descriptor->open_mode & O_RWMASK) == O_RDONLY)
+ return B_BAD_VALUE;
+
if (!HAS_FS_CALL(vnode, write_stat))
return B_READ_ONLY_DEVICE;
diff --git a/src/tests/system/libroot/posix/truncate.cpp
b/src/tests/system/libroot/posix/truncate.cpp
index c0256760d3..df1e94b2b0 100644
--- a/src/tests/system/libroot/posix/truncate.cpp
+++ b/src/tests/system/libroot/posix/truncate.cpp
@@ -6,6 +6,7 @@
#include <ctype.h>
#include <errno.h>
+#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -48,5 +49,19 @@ main(int argc, char **argv)
return 1;
}
+ int fd = open(argv[1], O_RDONLY);
+ if (fd < 0) {
+ fprintf(stderr, "%s: could open the file read-only \"%s\":
%s\n",
+ __progname, argv[1], strerror(errno));
+ return 1;
+ }
+ if (ftruncate(fd, newSize) == 0 || errno != EINVAL) {
+ fprintf(stderr, "%s: could truncate a file opened read-only
\"%s\": %s\n",
+ __progname, argv[1], strerror(errno));
+ close(fd);
+ return 1;
+ }
+ close(fd);
+
return 0;
}