aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Orlitzky <mjo@gentoo.org>2018-01-27 20:05:02 -0500
committerMike Gilbert <floppym@gentoo.org>2023-06-22 09:54:38 -0400
commit05e32f542c145253eb01ae4005ca13c63a1c79d8 (patch)
tree5fa501fd2fc41e5c324eebd7c0bef2b6d3157259 /tests/fchmod-0.c
parentlibsandbox: add support for fchown/fchmod on linux (diff)
downloadsandbox-05e32f542c145253eb01ae4005ca13c63a1c79d8.tar.gz
sandbox-05e32f542c145253eb01ae4005ca13c63a1c79d8.tar.bz2
sandbox-05e32f542c145253eb01ae4005ca13c63a1c79d8.zip
tests: add test case for fchown/fchmod with O_RDONLY.
Bug: https://bugs.gentoo.org/599706 Signed-off-by: Michael Orlitzky <mjo@gentoo.org> Signed-off-by: Mike Gilbert <floppym@gentoo.org>
Diffstat (limited to 'tests/fchmod-0.c')
-rw-r--r--tests/fchmod-0.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/fchmod-0.c b/tests/fchmod-0.c
new file mode 100644
index 0000000..de0c237
--- /dev/null
+++ b/tests/fchmod-0.c
@@ -0,0 +1,35 @@
+/*
+ * https://bugs.gentoo.org/599706
+ *
+ */
+
+#include "headers.h"
+
+int main(int argc, char *argv[])
+{
+ if (argc < 2)
+ return -2;
+
+ int mode = 0;
+ sscanf(argv[1], "%i", &mode);
+ /* The sandbox catches this:
+ *
+ * int fd = open(argv[2], O_RDWR);
+ *
+ * And it /should/ catch this:
+ *
+ * int fd = open(argv[2], O_RDONLY);
+ *
+ * ...but the latter only works when /proc/self/fd/%i
+ * is available.
+ *
+ */
+#ifdef SANDBOX_PROC_SELF_FD
+ int fd = open(argv[2], O_RDONLY);
+#else
+ int fd = open(argv[2], O_RDWR);
+#endif
+ int fchmod_result = fchmod(fd, (mode_t)mode);
+ close(fd);
+ return fchmod_result;
+}