[haiku-commits] haiku: hrev53113 - in src: tests/system/libroot/posix system/kernel/fs

  • From: Adrien Destugues <pulkomandy@xxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sun, 12 May 2019 03:23:23 -0400 (EDT)

hrev53113 adds 1 changeset to branch 'master'
old head: 00b283c04290a93c63b81aa91e2089bfd42a609f
new head: 858e5775ab6c58deed1c1280beae6267b581b8bc
overview: 
https://git.haiku-os.org/haiku/log/?qt=range&q=858e5775ab6c+%5E00b283c04290

----------------------------------------------------------------------------

858e5775ab6c: vfs: fail only truncate on file descriptors opened read-only.
  
  chmod is allowed.
  
  Change-Id: Idcac38bdd7f0d614538421a41dfd30066a0c316f
  Reviewed-on: https://review.haiku-os.org/c/1444
  Reviewed-by: Adrien Destugues <pulkomandy@xxxxxxxxx>
  Reviewed-by: Axel Dörfler <axeld@xxxxxxxxxxxxxxxx>

                                   [ Jérôme Duval <jerome.duval@xxxxxxxxx> ]

----------------------------------------------------------------------------

Revision:    hrev53113
Commit:      858e5775ab6c58deed1c1280beae6267b581b8bc
URL:         https://git.haiku-os.org/haiku/commit/?id=858e5775ab6c
Author:      Jérôme Duval <jerome.duval@xxxxxxxxx>
Date:        Fri May 10 18:42:20 2019 UTC
Committer:   Adrien Destugues <pulkomandy@xxxxxxxxx>
Commit-Date: Sun May 12 07:23:16 2019 UTC

----------------------------------------------------------------------------

3 files changed, 55 insertions(+), 1 deletion(-)
src/system/kernel/fs/vfs.cpp             |  5 ++-
src/tests/system/libroot/posix/Jamfile   |  1 +
src/tests/system/libroot/posix/chmod.cpp | 50 ++++++++++++++++++++++++++++

----------------------------------------------------------------------------

diff --git a/src/system/kernel/fs/vfs.cpp b/src/system/kernel/fs/vfs.cpp
index 4ac9022711..7ac6152b1c 100644
--- a/src/system/kernel/fs/vfs.cpp
+++ b/src/system/kernel/fs/vfs.cpp
@@ -26,6 +26,7 @@
 #include <fs_info.h>
 #include <fs_interface.h>
 #include <fs_volume.h>
+#include <NodeMonitor.h>
 #include <OS.h>
 #include <StorageDefs.h>
 
@@ -6606,8 +6607,10 @@ 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)
+       if ((descriptor->open_mode & O_RWMASK) == O_RDONLY
+               && (statMask & B_STAT_SIZE) != 0) {
                return B_BAD_VALUE;
+       }
 
        if (!HAS_FS_CALL(vnode, write_stat))
                return B_READ_ONLY_DEVICE;
diff --git a/src/tests/system/libroot/posix/Jamfile 
b/src/tests/system/libroot/posix/Jamfile
index 187dcb050f..054b4f694f 100644
--- a/src/tests/system/libroot/posix/Jamfile
+++ b/src/tests/system/libroot/posix/Jamfile
@@ -11,6 +11,7 @@ SimpleTest abort_test : abort_test.cpp ;
 SimpleTest SyslogTest : SyslogTest.cpp ;
 SimpleTest brk_test : brk_test.c ;
 SimpleTest calloc_test : calloc_test.c ;
+SimpleTest <test>chmod : chmod.cpp ;
 SimpleTest clearenv : clearenv.cpp ;
 SimpleTest dirent_test : dirent_test.cpp ;
 SimpleTest flock_test : flock_test.cpp ;
diff --git a/src/tests/system/libroot/posix/chmod.cpp 
b/src/tests/system/libroot/posix/chmod.cpp
new file mode 100644
index 0000000000..bdd4317551
--- /dev/null
+++ b/src/tests/system/libroot/posix/chmod.cpp
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2008, Axel Dörfler, axeld@xxxxxxxxxxxxxxxx.
+ * Distributed under the terms of the MIT License.
+ */
+
+
+#include <ctype.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+
+extern const char *__progname;
+
+
+int
+main(int argc, char **argv)
+{
+       if (argc < 3) {
+               fprintf(stderr, "usage: %s <file> <size>\n", __progname);
+               return 1;
+       }
+
+       struct stat st;
+       if (stat(argv[1], &st) != 0) {
+               fprintf(stderr, "%s: cannot stat file \"%s\": %s\n", __progname,
+                       argv[1], strerror(errno));
+               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 (fchmod(fd, 0666) == -1) {
+               fprintf(stderr, "%s: couldn't chmod a file opened read-only 
\"%s\": %s\n",
+                       __progname, argv[1], strerror(errno));
+               close(fd);
+               return 1;
+       }
+       close(fd);
+
+       return 0;
+}


Other related posts:

  • » [haiku-commits] haiku: hrev53113 - in src: tests/system/libroot/posix system/kernel/fs - Adrien Destugues