summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2021-08-11 13:41:49 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2021-08-11 13:41:49 +0000
commitf399f96e5186f8b486c6a1b7b46339530c3df45c (patch)
tree11e31b571e5f1945bf29967f02f0d17f107a3c1c /bin
parent0f1937155d100f77b69fd52de2cbea010f79c206 (diff)
If the -f argument includes %s, we need to use timegm(3) rather
than mktime(3) because the UNIX Epoch is defined in UTC rather than in the local timezone. Combining %s with other format specifiers is usually not useful. But if a user does that, then parsing the whole input as UTC seems better than parsing some of it as UTC and some of it in the local time zone. Bug found by Bryan Vyhmeister. The final patch is joint work with and OK by gerhard@. No objection when shown on tech@.
Diffstat (limited to 'bin')
-rw-r--r--bin/date/date.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/bin/date/date.c b/bin/date/date.c
index b197648716c..635c3f006d0 100644
--- a/bin/date/date.c
+++ b/bin/date/date.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: date.c,v 1.56 2019/08/08 02:17:51 cheloha Exp $ */
+/* $OpenBSD: date.c,v 1.57 2021/08/11 13:41:48 schwarze Exp $ */
/* $NetBSD: date.c,v 1.11 1995/09/07 06:21:05 jtc Exp $ */
/*
@@ -219,7 +219,11 @@ setthetime(char *p, const char *pformat)
}
/* convert broken-down time to UTC clock time */
- if ((tval = mktime(lt)) == -1)
+ if (pformat != NULL && strstr(pformat, "%s") != NULL)
+ tval = timegm(lt);
+ else
+ tval = mktime(lt);
+ if (tval == -1)
errx(1, "specified date is outside allowed range");
if (jflag)