]> git.ipfire.org Git - thirdparty/openssh-portable.git/commitdiff
upstream: ssh: use sentinel idiom for timegm(3) and mktime(3)
authortb@openbsd.org <tb@openbsd.org>
Wed, 27 May 2026 13:54:15 +0000 (13:54 +0000)
committerDamien Miller <djm@mindrot.org>
Sat, 30 May 2026 13:29:54 +0000 (23:29 +1000)
There is nothing wrong with times before the epoch, even -1, so use the
idiom recently added to the CAVEATS section to figure out whether there
was an error in the timegm() or mktime() calls.

We should sweep the tree for this. If anyone is bored, feel free to beat
me to it...

ok deraadt djm

OpenBSD-Commit-ID: e2b1721966dc782e776db5d6cfb18958534f9d4b

misc.c

diff --git a/misc.c b/misc.c
index ed3e9d31425c2a68bed223541d65e6800dc20a09..d9fd49dfa0be9b79d33be6b250f2bf78add177e9 100644 (file)
--- a/misc.c
+++ b/misc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: misc.c,v 1.213 2026/03/03 09:57:25 dtucker Exp $ */
+/* $OpenBSD: misc.c,v 1.214 2026/05/27 13:54:15 tb Exp $ */
 /*
  * Copyright (c) 2000 Markus Friedl.  All rights reserved.
  * Copyright (c) 2005-2020 Damien Miller.  All rights reserved.
@@ -2588,10 +2588,12 @@ parse_absolute_time(const char *s, uint64_t *tp)
        if ((cp = strptime(buf, fmt, &tm)) == NULL || *cp != '\0')
                return SSH_ERR_INVALID_FORMAT;
        if (is_utc) {
-               if ((tt = timegm(&tm)) < 0)
+               tm.tm_wday = -1;
+               if ((tt = timegm(&tm)) == -1 && tm.tm_wday == -1)
                        return SSH_ERR_INVALID_FORMAT;
        } else {
-               if ((tt = mktime(&tm)) < 0)
+               tm.tm_wday = -1;
+               if ((tt = mktime(&tm)) == -1 && tm.tm_wday == -1)
                        return SSH_ERR_INVALID_FORMAT;
        }
        /* success */