Skip to content

Commit

Permalink
gettimeofday01: test EFAULT error for single bad address tv/tz
Browse files Browse the repository at this point in the history
man-pages said that one of tv or tz pointed outside the accessible address space.

Signed-off-by: Yang Xu <[email protected]>
Reviewed-by: Li Wang <[email protected]>
  • Loading branch information
xuyang0410 authored and wangli5665 committed Dec 21, 2023
1 parent 0e81d78 commit fa9c169
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions testcases/kernel/syscalls/gettimeofday/gettimeofday01.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,36 @@
/*\
* [Description]
*
* Test for EFAULT error.
* Test for gettimeofday error.
*
* - gettimeofday fail with EFAULT when one of tv or tz pointed outside the accessible
* address space
* - EFAULT: tv pointed outside the accessible address space
* - EFAULT: tz pointed outside the accessible address space
* - EFAULT: both tv and tz pointed outside the accessible address space
*/

#include "tst_test.h"
#include "lapi/syscalls.h"

static void verify_gettimeofday(void)
static struct timeval tv1;

static struct tcase {
void *tv;
void *tz;
} tcases[] = {
/* timezone structure is obsolete, tz should be treated as null */
{(void *)-1, NULL},
{&tv1, (void *)-1},
{(void *)-1, (void *)-1},
};

static void verify_gettimeofday(unsigned int n)
{
TST_EXP_FAIL(tst_syscall(__NR_gettimeofday, (void *)-1, (void *)-1), EFAULT);
struct tcase *tc = &tcases[n];

TST_EXP_FAIL(tst_syscall(__NR_gettimeofday, tc->tv, tc->tz), EFAULT);
}

static struct tst_test test = {
.test_all = verify_gettimeofday,
.tcnt = ARRAY_SIZE(tcases),
.test = verify_gettimeofday,
};

0 comments on commit fa9c169

Please sign in to comment.