Do not format times that localtime_r and ctime_r cannot convert, from

Alexandre Fiori.

(cherry picked from commit c34432980f)
This commit is contained in:
nicm
2026-09-29 13:59:10 +00:00
committed by Nicholas Marriott
parent 6c11f706a3
commit 324ac927d6

View File

@@ -1,4 +1,4 @@
/* $OpenBSD: format.c,v 1.422 2026/09/29 11:57:28 nicm Exp $ */
/* $OpenBSD: format.c,v 1.423 2026/09/29 13:59:10 nicm Exp $ */
/*
* Copyright (c) 2011 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -4523,8 +4523,8 @@ format_pretty_time(time_t t, int seconds)
now = t;
age = now - t;
localtime_r(&now, &now_tm);
localtime_r(&t, &tm);
if (localtime_r(&now, &now_tm) == NULL || localtime_r(&t, &tm) == NULL)
return (xstrdup(""));
/* Last 24 hours. */
if (age < 24 * 3600) {
@@ -4695,10 +4695,12 @@ found:
found = format_pretty_time(t, 0);
else {
if (time_format != NULL) {
localtime_r(&t, &tm);
if (localtime_r(&t, &tm) == NULL)
return (NULL);
format_strftime(s, sizeof s, time_format, &tm);
} else {
ctime_r(&t, s);
if (ctime_r(&t, s) == NULL)
return (NULL);
s[strcspn(s, "\n")] = '\0';
}
found = xstrdup(s);