[RFC PATCH v3 02/14] tests/inject-nf.test: replace getpid with geteuid
Ákos Uzonyi
uzonyi.akos at gmail.com
Sat Jun 13 11:25:24 UTC 2020
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).
* tests/inject-nf.c: Replace getpid with geteuid.
[__alpha__]: Remove.
* tests/inject-nf.test: Replace getpid with geteuid.
Remove alpha workaround.
---
tests/inject-nf.c | 19 ++++++-------------
tests/inject-nf.test | 11 +----------
2 files changed, 7 insertions(+), 23 deletions(-)
diff --git a/tests/inject-nf.c b/tests/inject-nf.c
index c3774f6c..d49fd21b 100644
--- a/tests/inject-nf.c
+++ b/tests/inject-nf.c
@@ -16,28 +16,21 @@
#include "raw_syscall.h"
-#ifdef __alpha__
-/* alpha has no getpid */
-# define SC_NR __NR_getpgrp
-# define SC_NAME "getpgrp"
-# define getpid getpgrp
-#else
-# define SC_NR __NR_getpid
-# define SC_NAME "getpid"
-#endif
+#define SC_NR __NR_geteuid
+#define SC_NAME "geteuid"
#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 +38,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 cadb5adb..74ea3374 100755
--- a/tests/inject-nf.test
+++ b/tests/inject-nf.test
@@ -9,18 +9,9 @@
. "${srcdir=.}/scno_tampering.sh"
-case "$STRACE_ARCH" in
-alpha)
- SYSCALL=getpgrp
- ;;
-*)
- SYSCALL=getpid
- ;;
-esac
-
run_prog
prog="$args"
-fault_args="-a9 -e trace=${SYSCALL} -e inject=${SYSCALL}:retval="
+fault_args="-a9 -e trace=geteuid -e inject=geteuid:retval="
test_rval()
{
--
2.27.0
More information about the Strace-devel
mailing list