From: David Howells <dhowells@redhat.com>
To: keyrings@vger.kernel.org
Cc: dhowells@redhat.com, linux-security-module@vger.kernel.org,
John Stultz <john.stultz@linaro.org>,
linux-kernel@vger.kernel.org, Arnd Bergmann <arnd@arndb.de>
Subject: [RFC PATCH 2/4] Handle ISO 8601 leap seconds and encodings of midnight in mktime64()
Date: Mon, 04 Jan 2016 22:17:12 +0000 [thread overview]
Message-ID: <20160104221712.19818.69327.stgit@warthog.procyon.org.uk> (raw)
In-Reply-To: <20160104221658.19818.56223.stgit@warthog.procyon.org.uk>
Handle the following ISO 8601 features in mktime64():
(1) Leap seconds.
Leap seconds are indicated by the seconds parameter being the value
60. Handle this by treating it the same as 00 of the following
minute.
(2) Alternate encodings of midnight.
Two different encodings of midnight are permitted - 00:00:00 and
24:00:00 - the first is midnight today and the second is midnight
tomorrow and is exactly equivalent to the first with tomorrow's date.
As it happens, we don't actually need to change mktime64() to handle either
of these - just comment them as valid parameters.
These facility will be used by the X.509 parser. Doing it in mktime64()
makes the policy common to the whole kernel and easier to find.
Signed-off-by: David Howells <dhowells@redhat.com>
cc: Arnd Bergmann <arnd@arndb.de>
cc: John Stultz <john.stultz@linaro.org>
---
kernel/time/time.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/kernel/time/time.c b/kernel/time/time.c
index 86751c68e08d..be115b020d27 100644
--- a/kernel/time/time.c
+++ b/kernel/time/time.c
@@ -322,6 +322,13 @@ EXPORT_SYMBOL(timespec_trunc);
* -year/100+year/400 terms, and add 10.]
*
* This algorithm was first published by Gauss (I think).
+ *
+ * A leap second can be indicated by calling this function with sec as
+ * 60 (allowable under ISO 8601). The leap second is treated the same
+ * as the following second since they don't exist in UNIX time.
+ *
+ * An encoding of midnight at the end of the day as 24:00:00 - ie. midnight
+ * tomorrow - (allowable under ISO 8601) is supported.
*/
time64_t mktime64(const unsigned int year0, const unsigned int mon0,
const unsigned int day, const unsigned int hour,
@@ -338,7 +345,7 @@ time64_t mktime64(const unsigned int year0, const unsigned int mon0,
return ((((time64_t)
(year/4 - year/100 + year/400 + 367*mon/12 + day) +
year*365 - 719499
- )*24 + hour /* now have hours */
+ )*24 + hour /* now have hours - midnight tomorrow handled here */
)*60 + min /* now have minutes */
)*60 + sec; /* finally seconds */
}
next prev parent reply other threads:[~2016-01-04 22:17 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-04 22:16 [PATCH 0/4] X.509: Fix time handling David Howells
2016-01-04 22:17 ` [RFC PATCH 1/4] X.509: Fix leap year handling again David Howells
2016-01-20 15:12 ` Rudolf Polzer
2016-01-20 15:18 ` David Howells
2016-01-04 22:17 ` David Howells [this message]
2016-01-04 22:17 ` [RFC PATCH 3/4] X.509: Support leap seconds David Howells
2016-01-20 15:08 ` Rudolf Polzer
2016-01-04 22:17 ` [RFC PATCH 4/4] X.509: Handle midnight alternative notation in GeneralizedTime David Howells
2016-01-20 15:08 ` Rudolf Polzer
2016-01-20 15:20 ` David Howells
2016-01-20 15:30 ` One Thousand Gnomes
2016-02-03 16:25 ` David Howells
2016-02-03 16:28 ` David Howells
2016-02-04 17:38 ` One Thousand Gnomes
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160104221712.19818.69327.stgit@warthog.procyon.org.uk \
--to=dhowells@redhat.com \
--cc=arnd@arndb.de \
--cc=john.stultz@linaro.org \
--cc=keyrings@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).