It appears that localtime(3) is returning NULL and that is being
passed to strftime(). This should avoid the crash.
- todd
Index: bin/ls/print.c
===================================================================
RCS file: /cvs/src/bin/ls/print.c,v
retrieving revision 1.40
diff -u -p -u -r1.40 print.c
--- bin/ls/print.c 7 Oct 2023 11:51:08 -0000 1.40
+++ bin/ls/print.c 26 Mar 2024 19:44:04 -0000
@@ -241,6 +241,8 @@ static void
printtime(time_t ftime)
{
char f_date[DATELEN];
+ const char *fmt;
+ struct tm *tm;
static time_t now;
static int now_set = 0;
@@ -252,9 +254,11 @@ printtime(time_t ftime)
/*
* convert time to string, and print
*/
- if (strftime(f_date, sizeof(f_date), f_sectime ? "%b %e %H:%M:%S %Y" :
+ fmt = f_sectime ? "%b %e %H:%M:%S %Y" :
(ftime <= now - SIXMONTHS || ftime > now) ? "%b %e %Y" :
- "%b %e %H:%M", localtime(&ftime)) == 0)
+ "%b %e %H:%M";
+ tm = localtime(&ftime);
+ if (tm == NULL || strftime(f_date, sizeof(f_date), fmt, tm) == 0)
f_date[0] = '\0';
printf("%s ", f_date);