Project

General

Profile

Bug #6571

Time.mktime Y2K38 problem on 1.9.3p125 i386-mingw32

Added by Martin Bosslet about 4 years ago. Updated 3 months ago.

Status:
Closed
Priority:
Normal
Assignee:
openssl
ruby -v:
ruby 1.9.3p125 (2012-02-16) [i386-mingw32]
Backport:
[ruby-core:45552]

Description

=begin
This came up in https://bugs.ruby-lang.org/issues/6122.

(({Time.mktime(2038, 1, 19, 11, 14, 8)})) failed. To my understanding, 32 bit Time
issues shouldn't occur in 1.9.3? I'm assigning this to Luis, maybe he knows
about this and what to do? Please feel free to reassign back to me.
=end


Related issues

Related to Ruby trunk - Bug #6122: OpenSSL::PKCS7 verify Closed 03/07/2012

Associated revisions

Revision 55219
Added by rhe 3 months ago

openssl: use NUM2TIMET() to convert Integer to time_t

  • ext/openssl/ossl_asn1.c (time_to_time_t): Use NUM2TIMET() instead of NUM2LONG(). time_t may be larger than long. [Bug #6571]

Revision 55229
Added by rhe 3 months ago

openssl: add missing test for r55219

  • test/openssl/test_asn1.rb: Add missing regression test for r55219. It fixed the year 2038 issue but the test code was missing. [Bug #6571]

Revision 55249
Added by rhe 3 months ago

openssl: fix the Year 2038 problem

r55219 didn't fix the entire issue. It only fixed the issue on
environment with sizeof(time_t) == 8 && sizeof(long) == 4.

  • ext/openssl/extconf.rb: Check existence of ASN1_TIME_adj(). The old
    ASN1_TIME_set() is not Year 2038 ready on sizeof(time_t) == 4
    environment. This function was added in OpenSSL 1.0.0.
    [Bug #6571]

  • ext/openssl/ossl_asn1.c (ossl_time_split): Added. Split the argument
    (Time) into the number of days elapsed since the epoch and the
    remainder seconds to conform to ASN1_TIME_adj().
    (obj_to_asn1utime, obj_to_asn1gtime): Use ossl_time_split() and
    ASN1_*TIME_adj().

  • ext/openssl/ossl_asn1.h: Add the function prototype for
    ossl_time_split().

  • ext/openssl/ossl_x509.[ch]: Add ossl_x509_time_adjust(). Similarly to
    obj_to_asn1*time(), use X509_time_adj_ex() instead of X509_time_adj().

  • ext/openssl/ossl_x509cert.c, ext/openssl/ossl_x509crl.c,
    ext/openssl/ossl_x509revoked.c: Use ossl_x509_time_adjust().

History

#1 [ruby-core:45557] Updated by Nobuyoshi Nakada about 4 years ago

  • Target version changed from 2.0.0 to 1.9.3
  • Description updated (diff)
  • Status changed from Assigned to Feedback

I can't reproduce it with 1.9.3p216, in JST and PST.
What are the failure message and your timezone?

#2 [ruby-core:45556] Updated by Akira Tanaka about 4 years ago

2012/6/11 MartinBosslet (Martin Bosslet) Martin.Bosslet@googlemail.com:

Time.mktime(2038, 1, 19, 11, 14, 8) failed. To my understanding, 32 bit Time
issues shouldn't occur in 1.9.3? I'm assigning this to Luis, maybe he knows
about this and what to do? Please feel free to reassign back to me.

I couldn't reproduce the problem on GNU/Linux (x86_64 and i686).

% ./ruby -ve 'Time.mktime(2038, 1, 19, 11, 14, 8)'
ruby 2.0.0dev (2012-06-11 trunk 36028) [x86_64-linux]

% ./ruby -ve 'Time.mktime(2038, 1, 19, 11, 14, 8)'
ruby 2.0.0dev (2012-06-11 trunk 36030) [i686-linux]

So it seems platform dependent issue.

However I think you should show the actual result (failure message) and
your timezone, though.

Note that my timzone is +0900 (JST).
--
Tanaka Akira

#3 [ruby-core:45559] Updated by Heesob Park about 4 years ago

I guess it is not an issue of Time#mktime but an issue of OpenSSL.
Furthermore, the description is inaccurate.

Here is my test with ruby 1.9.3p194 (2012-04-20) [i386-mingw32]
C:\Ruby193\bin>irb
irb(main):001:0> require 'OpenSSL'
=> true
irb(main):002:0> cert = OpenSSL::X509::Certificate.new
=> #
irb(main):003:0> cert.not_after = Time.mktime(2038, 1, 19, 12, 14, 7)
=> 2038-01-19 12:14:07 +0900
irb(main):004:0> cert.not_after = Time.mktime(2038, 1, 19, 12, 14, 8)
RangeError: bignum too big to convert into long'
from (irb):4:in
not_after='
from (irb):4
from C:/Ruby193/bin/irb:12:in `'

I think that this error due to time_to_time_t function defined in ext/openssl/ossl_asn1.c

time_t
time_to_time_t(VALUE time)
{
return (time_t)NUM2LONG(rb_Integer(time));
}

#4 [ruby-core:45560] Updated by Nobuyoshi Nakada about 4 years ago

  • Assignee changed from Luis Lavena to Martin Bosslet
  • Status changed from Feedback to Assigned
  • Target version changed from 1.9.3 to 2.0.0

#5 [ruby-core:45576] Updated by Martin Bosslet about 4 years ago

  • Category changed from core to ext

Thanks for your analysis, guys. Makes sense now, why I couldn't reproduce it on 64 bits. The original #6122 did not contain the actual error that was raised, so thanks Heesob for pointing me towards the solution!

#6 [ruby-core:50622] Updated by Justin Peal over 3 years ago

Great thanks to all of you.

#7 [ruby-core:52456] Updated by Yusuke Endoh over 3 years ago

  • Target version changed from 2.0.0 to next minor

#8 Updated by Zachary Scott 12 months ago

  • Assignee changed from Martin Bosslet to openssl

#9 Updated by Anonymous 3 months ago

  • Status changed from Assigned to Closed

Applied in changeset r55219.


openssl: use NUM2TIMET() to convert Integer to time_t

  • ext/openssl/ossl_asn1.c (time_to_time_t): Use NUM2TIMET() instead of NUM2LONG(). time_t may be larger than long. [Bug #6571]

Also available in: Atom PDF