=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/ssh/misc.c,v retrieving revision 1.176 retrieving revision 1.177 diff -u -r1.176 -r1.177 --- src/usr.bin/ssh/misc.c 2022/06/03 04:30:47 1.176 +++ src/usr.bin/ssh/misc.c 2022/08/11 01:56:51 1.177 @@ -1,4 +1,4 @@ -/* $OpenBSD: misc.c,v 1.176 2022/06/03 04:30:47 djm Exp $ */ +/* $OpenBSD: misc.c,v 1.177 2022/08/11 01:56:51 djm Exp $ */ /* * Copyright (c) 2000 Markus Friedl. All rights reserved. * Copyright (c) 2005-2020 Damien Miller. All rights reserved. @@ -2299,15 +2299,26 @@ struct tm tm; time_t tt; char buf[32], *fmt; + const char *cp; + size_t l; + int is_utc = 0; *tp = 0; + l = strlen(s); + if (l > 1 && strcasecmp(s + l - 1, "Z") == 0) { + is_utc = 1; + l--; + } else if (l > 3 && strcasecmp(s + l - 3, "UTC") == 0) { + is_utc = 1; + l -= 3; + } /* * POSIX strptime says "The application shall ensure that there * is white-space or other non-alphanumeric characters between * any two conversion specifications" so arrange things this way. */ - switch (strlen(s)) { + switch (l) { case 8: /* YYYYMMDD */ fmt = "%Y-%m-%d"; snprintf(buf, sizeof(buf), "%.4s-%.2s-%.2s", s, s + 4, s + 6); @@ -2327,10 +2338,15 @@ } memset(&tm, 0, sizeof(tm)); - if (strptime(buf, fmt, &tm) == NULL) + if ((cp = strptime(buf, fmt, &tm)) == NULL || *cp != '\0') return SSH_ERR_INVALID_FORMAT; - if ((tt = mktime(&tm)) < 0) - return SSH_ERR_INVALID_FORMAT; + if (is_utc) { + if ((tt = timegm(&tm)) < 0) + return SSH_ERR_INVALID_FORMAT; + } else { + if ((tt = mktime(&tm)) < 0) + return SSH_ERR_INVALID_FORMAT; + } /* success */ *tp = (uint64_t)tt; return 0;