• David Howells's avatar
    X.509: Fix leap year handling again · 499f9ff8
    David Howells authored
    commit ac4cbedf upstream.
    
    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: default avatarRudolf Polzer <rpolzer@google.com>
    Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
    Acked-by: default avatarDavid Woodhouse <David.Woodhouse@intel.com>
    Acked-by: default avatarArnd Bergmann <arnd@arndb.de>
    Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
    499f9ff8
x509_cert_parser.c 16 KB