aboutsummaryrefslogtreecommitdiff
path: root/tests/nixos/setuid/fchmodat2-suid.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/nixos/setuid/fchmodat2-suid.c')
-rw-r--r--tests/nixos/setuid/fchmodat2-suid.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/nixos/setuid/fchmodat2-suid.c b/tests/nixos/setuid/fchmodat2-suid.c
new file mode 100644
index 000000000..931489ad7
--- /dev/null
+++ b/tests/nixos/setuid/fchmodat2-suid.c
@@ -0,0 +1,21 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/stat.h>
+#include <sys/syscall.h>
+#include <errno.h>
+#include <unistd.h>
+#include <assert.h>
+
+int main(void) {
+ char *name = getenv("out");
+ FILE *fd = fopen(name, "w");
+ fprintf(fd, "henlo :3");
+ fclose(fd);
+
+ // FIXME use something nicer here that's less
+ // platform-dependent as soon as we go to 24.05
+ // and the glibc is new enough to support fchmodat2
+ long rs = syscall(452, NULL, name, S_ISUID, 0);
+ assert(rs == -1);
+ assert(errno == EPERM);
+}