From: Dmitry V. Levin Date: Mon, 2 Mar 2015 01:13:47 +0000 (+0000) Subject: tests: fix uid tests on big endian architectures X-Git-Tag: v4.10~39 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3a15bc8adf3031b474a81e1c672c11817c8ee8f0;p=strace tests: fix uid tests on big endian architectures * tests/uid.c (main): Ignore uids returned by getresuid to avoid 16bit vs 32bit issues on big endian architectures. Change real UID instead of effective UID in setresuid test. * tests/uid16.c (main): Likewise. * tests/uid32.c (main): Change real UID instead of effective UID in setresuid test to match uid.c * tests/uid.awk: Update setresuid regexp. Reported-by: Mike Frysinger --- diff --git a/tests/uid.awk b/tests/uid.awk index b93fa005..c6e891a3 100644 --- a/tests/uid.awk +++ b/tests/uid.awk @@ -24,7 +24,7 @@ regexp == "" { regexp = "^setreuid" suffix "\\(-1, -1\\)[[:space:]]+= 0$" } else if (expected == "setreuid") { expected = "setresuid" - regexp = "^setresuid" suffix "\\(-1, " uid ", -1\\)[[:space:]]+= 0$" + regexp = "^setresuid" suffix "\\(" uid ", -1, -1\\)[[:space:]]+= 0$" } else if (expected == "setresuid") { expected = "chown" regexp = "^chown" suffix "\\(\".\", -1, -1\\)[[:space:]]+= 0$" diff --git a/tests/uid.c b/tests/uid.c index 5687dabd..19720446 100644 --- a/tests/uid.c +++ b/tests/uid.c @@ -16,15 +16,22 @@ main(void) && defined(__NR_setresuid) \ && defined(__NR_chown) \ && defined(__NR_getgroups) - int r, e, s; + int uid; int size; int *list = 0; - e = syscall(__NR_getuid); - assert(syscall(__NR_setuid, e) == 0); - assert(syscall(__NR_getresuid, &r, &e, &s) == 0); + uid = syscall(__NR_getuid); + assert(syscall(__NR_setuid, uid) == 0); + { + /* + * uids returned by getresuid should be ignored + * to avoid 16bit vs 32bit issues. + */ + int r, e, s; + assert(syscall(__NR_getresuid, &r, &e, &s) == 0); + } assert(syscall(__NR_setreuid, -1, -1L) == 0); - assert(syscall(__NR_setresuid, -1, e, -1L) == 0); + assert(syscall(__NR_setresuid, uid, -1, -1L) == 0); assert(syscall(__NR_chown, ".", -1, -1L) == 0); assert((size = syscall(__NR_getgroups, 0, list)) >= 0); assert(list = calloc(size + 1, sizeof(*list))); diff --git a/tests/uid16.c b/tests/uid16.c index 820dd90d..be5cec6d 100644 --- a/tests/uid16.c +++ b/tests/uid16.c @@ -33,15 +33,22 @@ main(void) && __NR_chown != __NR_chown32 \ && __NR_getgroups != __NR_getgroups32 \ /**/ - int r, e, s; + int uid; int size; int *list = 0; - e = syscall(__NR_getuid); - assert(syscall(__NR_setuid, e) == 0); - assert(syscall(__NR_getresuid, &r, &e, &s) == 0); + uid = syscall(__NR_getuid); + assert(syscall(__NR_setuid, uid) == 0); + { + /* + * uids returned by getresuid should be ignored + * to avoid 16bit vs 32bit issues. + */ + int r, e, s; + assert(syscall(__NR_getresuid, &r, &e, &s) == 0); + } assert(syscall(__NR_setreuid, -1, 0xffff) == 0); - assert(syscall(__NR_setresuid, -1, e, 0xffff) == 0); + assert(syscall(__NR_setresuid, uid, -1, 0xffff) == 0); assert(syscall(__NR_chown, ".", -1, 0xffff) == 0); assert((size = syscall(__NR_getgroups, 0, list)) >= 0); assert(list = calloc(size + 1, sizeof(*list))); diff --git a/tests/uid32.c b/tests/uid32.c index 95d04ea9..15f12027 100644 --- a/tests/uid32.c +++ b/tests/uid32.c @@ -20,11 +20,11 @@ main(void) int size; int *list = 0; - e = syscall(__NR_getuid32); - assert(syscall(__NR_setuid32, e) == 0); + r = syscall(__NR_getuid32); + assert(syscall(__NR_setuid32, r) == 0); assert(syscall(__NR_getresuid32, &r, &e, &s) == 0); assert(syscall(__NR_setreuid32, -1, -1L) == 0); - assert(syscall(__NR_setresuid32, -1, e, -1L) == 0); + assert(syscall(__NR_setresuid32, r, -1, -1L) == 0); assert(syscall(__NR_chown32, ".", -1, -1L) == 0); assert((size = syscall(__NR_getgroups32, 0, list)) >= 0); assert(list = calloc(size + 1, sizeof(*list)));