[LTP] [PATCH] gettimeofday01: test EFAULT error for single bad address tv/tz

Yang Xu xuyang2018.jy@fujitsu.com
Tue Dec 19 06:48:03 CET 2023


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(-)

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,
 };
-- 
2.27.0



More information about the ltp mailing list