diff mbox series

gettimeofday01: test EFAULT error for single bad address tv/tz

Message ID 20231219054803.136732-1-xuyang2018.jy@fujitsu.com
State Accepted
Headers show
Series gettimeofday01: test EFAULT error for single bad address tv/tz | expand

Commit Message

Yang Xu \(Fujitsu\) Dec. 19, 2023, 5:48 a.m. UTC
man-pages said that one of TV or tz pointed outside the accessible address space.

Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
 .../syscalls/gettimeofday/gettimeofday01.c    | 27 ++++++++++++++++---
 1 file changed, 23 insertions(+), 4 deletions(-)

Comments

Li Wang Dec. 21, 2023, 10:09 a.m. UTC | #1
Pushed with the description polishing, thank you!
diff mbox series

Patch

diff --git a/testcases/kernel/syscalls/gettimeofday/gettimeofday01.c b/testcases/kernel/syscalls/gettimeofday/gettimeofday01.c
index 3155beec9..adf4a7466 100644
--- a/testcases/kernel/syscalls/gettimeofday/gettimeofday01.c
+++ b/testcases/kernel/syscalls/gettimeofday/gettimeofday01.c
@@ -9,18 +9,37 @@ 
  *
  * Test for EFAULT error.
  *
- * - gettimeofday fail with EFAULT when one of tv or tz pointed outside the accessible
+ * - gettimeofday fail with EFAULT when tv pointed outside the accessible
+ *   address space
+ * - gettimeofday fail with EFAULT when tz pointed outside the accessible
+ *   address space
+ * - gettimeofday fail with EFAULT when 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,
 };