]> granicus.if.org Git - strace/commitdiff
tests/uid: import uid overflow check from tests/uid16
authorDmitry V. Levin <ldv@altlinux.org>
Wed, 22 Jul 2015 19:31:54 +0000 (19:31 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Wed, 22 Jul 2015 19:47:39 +0000 (19:47 +0000)
* tests/uid.c (main): Skip if the uid returned by getuid matches
/proc/sys/kernel/overflowuid.

tests/uid.c

index f316d805dfb66411cab2cc707f2f67fe0e7464cc..bf4d8d2288534399ba7e86636f6d59d96e2058f9 100644 (file)
@@ -4,6 +4,7 @@
 #include <assert.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <fcntl.h>
 #include <sys/syscall.h>
 
 int
@@ -24,6 +25,21 @@ main(void)
 # define __NR_getuid __NR_getxuid
 #endif
        uid = syscall(__NR_getuid);
+
+       (void) close(0);
+       if (open("/proc/sys/kernel/overflowuid", O_RDONLY) == 0) {
+               /* we trust the kernel */
+               char buf[sizeof(int)*3];
+               int n = read(0, buf, sizeof(buf) - 1);
+               if (n) {
+                       buf[n] = '\0';
+                       n = atoi(buf);
+                       if (uid == n)
+                               return 77;
+               }
+               (void) close(0);
+       }
+
        assert(syscall(__NR_setuid, uid) == 0);
        {
                /*