]> git.ipfire.org Git - thirdparty/openssh-portable.git/commitdiff
upstream: Handle localtime_r() failure by return "UNKNOWN-TIME"
authorderaadt@openbsd.org <deraadt@openbsd.org>
Mon, 11 Aug 2025 14:37:43 +0000 (14:37 +0000)
committerDamien Miller <djm@mindrot.org>
Tue, 12 Aug 2025 23:20:40 +0000 (09:20 +1000)
which is only used in user-visible contexts.  freebsd 288773 shows their
localtime_r() has failed at least once for unknown reason. discussed with djm

OpenBSD-Commit-ID: 68f4c92d46b2578d4594b0ed940958d597fd61ac

misc.c

diff --git a/misc.c b/misc.c
index 838a7f788a7fd19a80f97038aeea5c276576c7d0..2e77eeb88de4e914c7a2ca92c0faa4e50f68b9b8 100644 (file)
--- a/misc.c
+++ b/misc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: misc.c,v 1.201 2025/07/31 11:23:39 job Exp $ */
+/* $OpenBSD: misc.c,v 1.202 2025/08/11 14:37:43 deraadt Exp $ */
 /*
  * Copyright (c) 2000 Markus Friedl.  All rights reserved.
  * Copyright (c) 2005-2020 Damien Miller.  All rights reserved.
@@ -2540,8 +2540,10 @@ format_absolute_time(uint64_t t, char *buf, size_t len)
        time_t tt = t > SSH_TIME_T_MAX ? SSH_TIME_T_MAX : t;
        struct tm tm;
 
-       localtime_r(&tt, &tm);
-       strftime(buf, len, "%Y-%m-%dT%H:%M:%S", &tm);
+       if (localtime_r(&tt, &tm) == NULL)
+               strlcpy(buf, "UNKNOWN-TIME", len);
+       else
+               strftime(buf, len, "%Y-%m-%dT%H:%M:%S", &tm);
 }
 
 /*