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 <vapier@gentoo.org>
This commit is contained in:
Дмитрий Левин 2015-03-02 01:13:47 +00:00
parent a8dcf253fa
commit 3a15bc8adf
4 changed files with 28 additions and 14 deletions

View File

@ -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$"

View File

@ -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)));

View File

@ -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)));

View File

@ -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)));