summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÁkos Uzonyi <uzonyi.akos@gmail.com>2020-06-19 12:06:42 +0200
committerDmitry V. Levin <ldv@altlinux.org>2020-06-16 21:00:00 +0000
commit82005acc54b182d4a56c7c166948814d9e4d1cc3 (patch)
tree9a7383faa9ac5cec7e349fb3abe0409f656c1c95
parent86a53f791ad34a825b8633eb0272d954647ce705 (diff)
downloadstrace-82005acc54b182d4a56c7c166948814d9e4d1cc3.tar.gz
tests/inject-nf.test: replace getpid with geteuid
Since we treat PIDs as signed integers, large values (>=2^31) will cause overflow when we use printpid. UIDs are treated as unsigned integers, so geteuid is a good alternative. (getuid would be problematic, as it does not exists on alpha). Also, on systems where geteuid32 exists, geteuid returns maximum 16 bit values, so we have to use geteuid32 in this case. [ldv: geteuid syscall was introduced on Alpha by Linux kernel commit v5.1-rc1~160^2~3^2~1, so this test will not work on old Alpha kernels.] * tests/inject-nf.c: Replace getpid with either geteuid32 or geteuid. [__alpha__]: Remove. [__NR_geteuid32]: New condition. * tests/inject-nf.test (SYSCALL): Replace getpid with '/^geteuid(32)?$'. Remove alpha workaround.
-rw-r--r--tests/inject-nf.c20
-rwxr-xr-xtests/inject-nf.test9
2 files changed, 10 insertions, 19 deletions
diff --git a/tests/inject-nf.c b/tests/inject-nf.c
index c3774f6c1..dc11b87b9 100644
--- a/tests/inject-nf.c
+++ b/tests/inject-nf.c
@@ -16,28 +16,26 @@
#include "raw_syscall.h"
-#ifdef __alpha__
-/* alpha has no getpid */
-# define SC_NR __NR_getpgrp
-# define SC_NAME "getpgrp"
-# define getpid getpgrp
+#ifdef __NR_geteuid32
+# define SC_NR __NR_geteuid32
+# define SC_NAME "geteuid32"
#else
-# define SC_NR __NR_getpid
-# define SC_NAME "getpid"
+# define SC_NR __NR_geteuid
+# define SC_NAME "geteuid"
#endif
#ifdef raw_syscall_0
# define INVOKE_SC(err) raw_syscall_0(SC_NR, &err)
#else
-/* No raw_syscall_0, let's use getpid() and hope for the best. */
-# define INVOKE_SC(err) getpid()
+/* No raw_syscall_0, let's use geteuid() and hope for the best. */
+# define INVOKE_SC(err) geteuid()
#endif
/*
* This prototype is intentionally different
* from the prototype provided by <unistd.h>.
*/
-extern kernel_ulong_t getpid(void);
+extern kernel_ulong_t geteuid(void);
int
main(int ac, char **av)
@@ -45,7 +43,7 @@ main(int ac, char **av)
assert(ac == 1 || ac == 2);
kernel_ulong_t expected =
- (ac == 1) ? getpid() : strtoull(av[1], NULL, 0);
+ (ac == 1) ? geteuid() : strtoull(av[1], NULL, 0);
kernel_ulong_t err = 0;
kernel_ulong_t rc = INVOKE_SC(err);
diff --git a/tests/inject-nf.test b/tests/inject-nf.test
index cadb5adb0..90772d6ca 100755
--- a/tests/inject-nf.test
+++ b/tests/inject-nf.test
@@ -9,14 +9,7 @@
. "${srcdir=.}/scno_tampering.sh"
-case "$STRACE_ARCH" in
-alpha)
- SYSCALL=getpgrp
- ;;
-*)
- SYSCALL=getpid
- ;;
-esac
+SYSCALL='/^geteuid(32)?$'
run_prog
prog="$args"