From 8b6c1f402feb9eb6438003a312d7ffe8d5669896 Mon Sep 17 00:00:00 2001 From: "deraadt@openbsd.org" Date: Mon, 11 Aug 2025 14:37:43 +0000 Subject: [PATCH] upstream: Handle localtime_r() failure by return "UNKNOWN-TIME" 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 | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/misc.c b/misc.c index 838a7f788..2e77eeb88 100644 --- 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); } /* -- 2.47.3