code: plan9front

Download patch

ref: b959508d906a6f7c98fe03b8bfd520370061f20f
parent: 10b25b512218fa7fc7b9239bf7f70b03bbd7f4ab
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Mon Feb 12 20:21:04 EST 2024

ext4srv: disallow fwrite/ftruncate on files not open for writing

--- a/sys/src/cmd/ext4srv/ext4.c
+++ b/sys/src/cmd/ext4srv/ext4.c
@@ -1566,7 +1566,7 @@
 		return -1;
 	}
 
-	if (f->flags & O_RDONLY) {
+	if ((f->flags & O_WRMASK) == 0) {
 		werrstr(Eperm);
 		return -1;
 	}
@@ -1770,7 +1770,7 @@
 		return -1;
 	}
 
-	if (file->flags & O_RDONLY) {
+	if ((file->flags & O_WRMASK) == 0) {
 		werrstr(Eperm);
 		return -1;
 	}
--- a/sys/src/cmd/ext4srv/include/ext4_config.h
+++ b/sys/src/cmd/ext4srv/include/ext4_config.h
@@ -13,6 +13,8 @@
 	O_EXCL = 0200,
 	O_TRUNC = 01000,
 	O_APPEND = 02000,
+
+	O_WRMASK = O_WRONLY | O_RDWR,
 };
 
 #if defined(__mips__) || defined(__power__) || defined(__power64__) || defined(__sparc__) || defined(__sparc64__)