From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933700AbbLRACY (ORCPT ); Thu, 17 Dec 2015 19:02:24 -0500 Received: from mx1.redhat.com ([209.132.183.28]:49691 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933395AbbLRACT (ORCPT ); Thu, 17 Dec 2015 19:02:19 -0500 Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 Subject: [PATCH 4/5] Handle both ISO 8601 encodings of midnight in mktime64() From: David Howells To: keyrings@vger.kernel.org Cc: Arnd Bergmann , linux-kernel@vger.kernel.org, stable@vger.kernel.org, dhowells@redhat.com, linux-security-module@vger.kernel.org, John Stultz Date: Fri, 18 Dec 2015 00:02:17 +0000 Message-ID: <20151218000217.29483.43671.stgit@warthog.procyon.org.uk> In-Reply-To: <20151218000148.29483.67155.stgit@warthog.procyon.org.uk> References: <20151218000148.29483.67155.stgit@warthog.procyon.org.uk> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ISO 8601 format dates permit two different encodings of midnight - 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. Note that the implementation of mktime64() doesn't actually need to be changed to handle this - the multiplication by 3600 of the hour will take care of it automatically. However, we should document that this handling is done in mktime64() and is thus in a common place in the kernel. This handling is required for X.509 certificate parsing which can be given ISO 8601 dates. Signed-off-by: David Howells cc: John Stultz cc: Arnd Bergmann cc: stable@vger.kernel.org --- kernel/time/time.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/kernel/time/time.c b/kernel/time/time.c index 1858b10602f5..56e7ada38471 100644 --- a/kernel/time/time.c +++ b/kernel/time/time.c @@ -326,6 +326,9 @@ EXPORT_SYMBOL(timespec_trunc); * 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 preceding 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(unsigned int year0, unsigned int mon0, unsigned int day, unsigned int hour, @@ -346,7 +349,7 @@ time64_t mktime64(unsigned int year0, 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 */ }