All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Howells <dhowells@redhat.com>
To: keyrings@vger.kernel.org
Cc: David Woodhouse <David.Woodhouse@intel.com>,
	linux-kernel@vger.kernel.org, stable@vger.kernel.org,
	dhowells@redhat.com, linux-security-module@vger.kernel.org,
	Rudolf Polzer <rpolzer@google.com>
Subject: [RFC PATCH 1/4] X.509: Fix leap year handling again
Date: Mon, 04 Jan 2016 22:17:05 +0000	[thread overview]
Message-ID: <20160104221705.19818.67138.stgit@warthog.procyon.org.uk> (raw)
In-Reply-To: <20160104221658.19818.56223.stgit@warthog.procyon.org.uk>

There are still a couple of minor issues in the X.509 leap year handling:

 (1) To avoid doing a modulus-by-400 in addition to a modulus-by-100 when
     determining whether the year is a leap year or not, I divided the year
     by 100 after doing the modulus-by-100, thereby letting the compiler do
     one instruction for both, and then did a modulus-by-4.

     Unfortunately, I then passed the now-modified year value to mktime64()
     to construct a time value.

     Since this isn't a fast path and since mktime64() does a bunch of
     divisions, just condense down to "% 400".  It's also easier to read.

 (2) The default month length for any February where the year doesn't
     divide by four exactly is obtained from the month_length[] array where
     the value is 29, not 28.

     This is fixed by altering the table.

Reported-by: Rudolf Polzer <rpolzer@google.com>
Signed-off-by: David Howells <dhowells@redhat.com>
Acked-By: David Woodhouse <David.Woodhouse@intel.com>
cc: stable@vger.kernel.org
---

 crypto/asymmetric_keys/x509_cert_parser.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/crypto/asymmetric_keys/x509_cert_parser.c b/crypto/asymmetric_keys/x509_cert_parser.c
index 021d39c0ba75..13c4e5a5fe8c 100644
--- a/crypto/asymmetric_keys/x509_cert_parser.c
+++ b/crypto/asymmetric_keys/x509_cert_parser.c
@@ -494,7 +494,7 @@ int x509_decode_time(time64_t *_t,  size_t hdrlen,
 		     unsigned char tag,
 		     const unsigned char *value, size_t vlen)
 {
-	static const unsigned char month_lengths[] = { 31, 29, 31, 30, 31, 30,
+	static const unsigned char month_lengths[] = { 31, 28, 31, 30, 31, 30,
 						       31, 31, 30, 31, 30, 31 };
 	const unsigned char *p = value;
 	unsigned year, mon, day, hour, min, sec, mon_len;
@@ -540,9 +540,9 @@ int x509_decode_time(time64_t *_t,  size_t hdrlen,
 		if (year % 4 == 0) {
 			mon_len = 29;
 			if (year % 100 == 0) {
-				year /= 100;
-				if (year % 4 != 0)
-					mon_len = 28;
+				mon_len = 28;
+				if (year % 400 == 0)
+					mon_len = 29;
 			}
 		}
 	}


  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 ` David Howells [this message]
2016-01-20 15:12   ` [RFC PATCH 1/4] X.509: Fix leap year handling again Rudolf Polzer
2016-01-20 15:18   ` David Howells
2016-01-04 22:17 ` [RFC PATCH 2/4] Handle ISO 8601 leap seconds and encodings of midnight in mktime64() David Howells
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=20160104221705.19818.67138.stgit@warthog.procyon.org.uk \
    --to=dhowells@redhat.com \
    --cc=David.Woodhouse@intel.com \
    --cc=keyrings@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=rpolzer@google.com \
    --cc=stable@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.