[LTP] [PATCH] syscalls/stime: Fix Time Overflow for 2038 Problem on 32-bit Systems
Cyril Hrubis
chrubis@suse.cz
Fri Jul 11 17:32:05 CEST 2025
Hi!
> Signed-off-by: Jiaying Song <jiaying.song.cn@windriver.com>
> ---
> testcases/kernel/syscalls/stime/stime01.c | 10 +++++-----
> testcases/kernel/syscalls/stime/stime_var.h | 4 ++--
> 2 files changed, 7 insertions(+), 7 deletions(-)
>
> diff --git a/testcases/kernel/syscalls/stime/stime01.c b/testcases/kernel/syscalls/stime/stime01.c
> index 82a340258..9e909d7ca 100644
> --- a/testcases/kernel/syscalls/stime/stime01.c
> +++ b/testcases/kernel/syscalls/stime/stime01.c
> @@ -33,7 +33,7 @@ static void run(void)
> new_time = real_time_tv.tv_sec + 30;
>
> if (do_stime(&new_time) < 0) {
> - tst_res(TFAIL | TERRNO, "stime(%ld) failed", new_time);
> + tst_res(TFAIL | TERRNO, "stime(%jd) failed", (intmax_t)new_time);
> return;
> }
>
> @@ -43,12 +43,12 @@ static void run(void)
> switch (pres_time_tv.tv_sec - new_time) {
> case 0:
> case 1:
> - tst_res(TINFO, "pt.tv_sec: %ld", pres_time_tv.tv_sec);
> - tst_res(TPASS, "system time was set to %ld", new_time);
> + tst_res(TINFO, "pt.tv_sec: %jd", (intmax_t)pres_time_tv.tv_sec);
> + tst_res(TPASS, "system time was set to %jd", (intmax_t)new_time);
> break;
> default:
> - tst_res(TFAIL, "system time not set to %ld (got: %ld)",
> - new_time, pres_time_tv.tv_sec);
> + tst_res(TFAIL, "system time not set to %jd (got: %jd)",
> + (intmax_t)new_time, (intmax_t)pres_time_tv.tv_sec);
> }
> }
>
> diff --git a/testcases/kernel/syscalls/stime/stime_var.h b/testcases/kernel/syscalls/stime/stime_var.h
> index 708b80573..326240972 100644
> --- a/testcases/kernel/syscalls/stime/stime_var.h
> +++ b/testcases/kernel/syscalls/stime/stime_var.h
> @@ -27,12 +27,12 @@ static int do_stime(time_t *ntime)
> case 1:
> return tst_syscall(__NR_stime, ntime);
> case 2: {
> - struct __kernel_old_timeval tv;
> + struct timeval tv;
>
> tv.tv_sec = *ntime;
> tv.tv_usec = 0;
>
> - return tst_syscall(__NR_settimeofday, &tv, (struct timezone *) 0);
> + return settimeofday(&tv, (struct timezone *) 0);
The point of this code is to call all possible kernel variants, so we
cant just change it like this.
I guess that the easiest fix is to set the new_time to a fixed value
that is not going to overflow.
Something like:
diff --git a/testcases/kernel/syscalls/stime/stime01.c b/testcases/kernel/syscalls/stime/stime01.c
index 82a340258..12b7ccb39 100644
--- a/testcases/kernel/syscalls/stime/stime01.c
+++ b/testcases/kernel/syscalls/stime/stime01.c
@@ -20,17 +20,12 @@
#include "tst_test.h"
#include "stime_var.h"
-static struct timeval real_time_tv;
-
static void run(void)
{
time_t new_time;
struct timeval pres_time_tv;
- if (gettimeofday(&real_time_tv, NULL) < 0)
- tst_brk(TBROK | TERRNO, "gettimeofday() failed");
-
- new_time = real_time_tv.tv_sec + 30;
+ new_time = 1752247867;
--
Cyril Hrubis
chrubis@suse.cz
More information about the ltp
mailing list