[openssh-commits] [openssh] 04/07: upstream: ssh: use sentinel idiom for timegm(3) and mktime(3)

git+noreply at mindrot.org git+noreply at mindrot.org
Sat May 30 23:30:30 AEST 2026


This is an automated email from the git hooks/post-receive script.

djm pushed a commit to branch master
in repository openssh.

commit 3bee4a1a260809992a0877d7ef202c4ff3e0be24
Author: tb at openbsd.org <tb at openbsd.org>
AuthorDate: Wed May 27 13:54:15 2026 +0000

    upstream: ssh: use sentinel idiom for timegm(3) and mktime(3)
    
    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 | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/misc.c b/misc.c
index ed3e9d314..d9fd49dfa 100644
--- 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 */

-- 
To stop receiving notification emails like this one, please contact
djm at mindrot.org.


More information about the openssh-commits mailing list