From 2d6925708e3da420b8cce394bc27b997754ba98e Mon Sep 17 00:00:00 2001 From: Michael Pfeifroth Date: Thu, 5 Nov 2026 15:33:22 +0100 Subject: [PATCH] awk: fix mktime() for dates beyond 2038 do_mktime() returned the result of mktime() as int. Since int is 32 bits wide even on LP64 systems, any time at or after 2038-01-19 03:14:08 UTC was truncated, even with a 64-bit time_t: $ TZ=UTC busybox awk 'BEGIN { printf "%.0f\n", mktime("2038 01 19 03 14 08") }' -2147483648 Return time_t instead and add a testcase. function old new delta exec_builtin 1130 1136 +6 do_mktime 119 121 +2 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/0 up/down: 8/0) Total: 8 bytes Signed-off-by: Michael Pfeifroth Signed-off-by: Denys Vlasenko --- editors/awk.c | 2 +- testsuite/awk.tests | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/editors/awk.c b/editors/awk.c index f8e20679c..7943f2cd6 100644 --- a/editors/awk.c +++ b/editors/awk.c @@ -2914,7 +2914,7 @@ static int awk_sub(node *rn, const char *repl, int nm, var *src, var *dest /*,in return match_no; } -static NOINLINE int do_mktime(const char *ds) +static NOINLINE time_t do_mktime(const char *ds) { struct tm then; int count; diff --git a/testsuite/awk.tests b/testsuite/awk.tests index e2c042687..a1995c1c0 100755 --- a/testsuite/awk.tests +++ b/testsuite/awk.tests @@ -828,4 +828,11 @@ testing 'awk gensub backslash*8 + & in replacement' 'awk '$sq'{ print gensub(/b testing 'awk gensub backslash*10 + & in replacement' 'awk '$sq'{ print gensub(/b/, "_\\\\\\\\\\&_", 1) }'$sq 'a_\\\\&_c\n' '' 'abc\n' testing 'awk gensub backslash*12 + & in replacement' 'awk '$sq'{ print gensub(/b/, "_\\\\\\\\\\\\&_", 1) }'$sq 'a_\\\\\\b_c\n' '' 'abc\n' +optional TIME64 +testing "awk mktime() beyond 2038" \ + "TZ=UTC awk 'BEGIN { printf \"%.0f %.0f\\n\", mktime(\"2038 01 19 03 14 08\"), mktime(\"2040 01 01 00 00 00\") }'" \ + "2147483648 2208988800\n" \ + "" "" +SKIP= + exit $FAILCOUNT