From fbe1a9ec6e90d06f173ba849d136ae677db20a12 Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Tue, 19 Apr 2016 17:30:23 +0000 Subject: [PATCH] tests: extend test coverage of getresuid syscall * tests/getresugid.c: New file. * tests/getresuid.c: New file. * tests/getresuid.test: New test. * tests/.gitignore: Add getresuid. * tests/Makefile.am (check_PROGRAMS): Likewise. (DECODER_TESTS): Add getresuid.test. (EXTRA_DIST): Add getresugid.c. --- tests/.gitignore | 1 + tests/Makefile.am | 3 +++ tests/getresugid.c | 60 ++++++++++++++++++++++++++++++++++++++++++++ tests/getresuid.c | 21 ++++++++++++++++ tests/getresuid.test | 6 +++++ 5 files changed, 91 insertions(+) create mode 100644 tests/getresugid.c create mode 100644 tests/getresuid.c create mode 100755 tests/getresuid.test diff --git a/tests/.gitignore b/tests/.gitignore index 87ef8a92..e1491a95 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -62,6 +62,7 @@ getdents64 getgroups getgroups32 getrandom +getresuid getrusage getxxid inet-cmsg diff --git a/tests/Makefile.am b/tests/Makefile.am index 6f515daf..a29e71a3 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -114,6 +114,7 @@ check_PROGRAMS = \ getgroups \ getgroups32 \ getrandom \ + getresuid \ getrusage \ getxxid \ inet-cmsg \ @@ -350,6 +351,7 @@ DECODER_TESTS = \ getgroups.test \ getgroups32.test \ getrandom.test \ + getresuid.test \ getrusage.test \ getxxid.test \ inet-cmsg.test \ @@ -540,6 +542,7 @@ EXTRA_DIST = init.sh run.sh match.awk \ filter-unavailable.expected \ fstatat.c \ fstatx.c \ + getresugid.c \ ip_mreq.expected \ ipc.sh \ ipc_msgbuf.expected \ diff --git a/tests/getresugid.c b/tests/getresugid.c new file mode 100644 index 00000000..13501ba7 --- /dev/null +++ b/tests/getresugid.c @@ -0,0 +1,60 @@ +/* + * Check decoding of getresuid/getresgid/getresuid32/getresgid32 syscalls. + * + * Copyright (c) 2016 Dmitry V. Levin + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include + +int +main(void) +{ + unsigned UGID_TYPE *const r = tail_alloc(sizeof(*r)); + unsigned UGID_TYPE *const e = tail_alloc(sizeof(*e)); + unsigned UGID_TYPE *const s = tail_alloc(sizeof(*s)); + (void) tail_alloc(1); + + if (syscall(SYSCALL_NR, r, e, s)) + perror_msg_and_fail(SYSCALL_NAME); + + printf("%s([%u], [%u], [%u]) = 0\n", SYSCALL_NAME, + (unsigned) *r, (unsigned) *e, (unsigned) *s); + + assert(syscall(SYSCALL_NR, NULL, e, s) == -1); + printf("%s(NULL, %p, %p) = -1 EFAULT (%m)\n", SYSCALL_NAME, e, s); + + assert(syscall(SYSCALL_NR, r, NULL, s) == -1); + printf("%s(%p, NULL, %p) = -1 EFAULT (%m)\n", SYSCALL_NAME, r, s); + + assert(syscall(SYSCALL_NR, r, e, NULL) == -1); + printf("%s(%p, %p, NULL) = -1 EFAULT (%m)\n", SYSCALL_NAME, r, e); + + puts("+++ exited with 0 +++"); + return 0; +} diff --git a/tests/getresuid.c b/tests/getresuid.c new file mode 100644 index 00000000..bf4ada17 --- /dev/null +++ b/tests/getresuid.c @@ -0,0 +1,21 @@ +#include "tests.h" +#include + +#ifdef __NR_getresuid + +# define SYSCALL_NR __NR_getresuid +# define SYSCALL_NAME "getresuid" + +# if defined __NR_getresuid32 && __NR_getresuid != __NR_getresuid32 +# define UGID_TYPE short +# else +# define UGID_TYPE int +# endif + +# include "getresugid.c" + +#else + +SKIP_MAIN_UNDEFINED("__NR_getresuid") + +#endif diff --git a/tests/getresuid.test b/tests/getresuid.test new file mode 100755 index 00000000..eee1ac05 --- /dev/null +++ b/tests/getresuid.test @@ -0,0 +1,6 @@ +#!/bin/sh + +# Check getresuid syscall decoding. + +. "${srcdir=.}/init.sh" +run_strace_match_diff -a25 -- 2.40.0