[PATCH] awk: fix mktime for 2038

Sertonix via busybox <[email protected]> Thu, 23 Apr 2026 18:14:21 +0000
Newsgroups gmane.linux.busybox
Message-ID <[email protected]>
Dates in 2038 (and later) would overflow to negative. time_t is the
return type of mktime(3) which should make overflow of the return value
impossible.

Without patch:
$ busybox awk 'BEGIN{ print(mktime("2038 01 20 01 01 01")); }'
-2147408835

With patch:
$ busybox awk 'BEGIN{ print(mktime("2038 01 20 01 01 01")); }'
2147558461

function                                             old     new   delta
exec_builtin                                        1235    1237      +2
do_mktime                                            161     159      -2
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 2/-2)                Total: 0 bytes

---
 editors/awk.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/editors/awk.c b/editors/awk.c
index dd8f4ac42..5f7df5c9f 100644
--- a/editors/awk.c
+++ b/editors/awk.c
@@ -2663,7 +2663,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;
-- 
2.54.0