Repository navigation
Fix time conversions - #1139
Fix time conversions#1139nobu wants to merge 2 commits into
Conversation
Use the dedicated macro `NUM2TIMET` for `time_t`, and `FIX2LEN` for Fixnum values that are not limited to `time_t`.
There was a problem hiding this comment.
🟡 Changes recommended
Active critical compatibility and moderate test-coverage issues remain unresolved, including missing fallbacks for the new time-conversion APIs and no regression case for timestamps exceeding 32-bit limits.
2 open issues
What changed in this PR
Updates OpenSSL time handling to preserve time_t width and use newer OpenSSL APIs where available, improving support for timestamps beyond platform long limits.
Changes:
- Adds compatibility support for
FIX2LEN. - Uses
NUM2TIMETandTIMET2NUMfortime_tvalues. - Detects and uses OpenSSL
_exAPIs with legacy fallbacks. - Updates ASN.1 timestamp splitting to preserve wider values.
| File | Summary |
|---|---|
ext/openssl/ossl.h |
Adds compatibility support for length-based Fixnum conversion. |
ext/openssl/ossl_x509store.c |
Uses time_t-aware conversions for X.509 verification times. |
ext/openssl/ossl_ssl.c |
Uses time_t conversion and conditionally calls SSL_CTX_flush_sessions_ex. |
ext/openssl/ossl_ssl_session.c |
Uses time_t storage and OpenSSL session _ex APIs. |
ext/openssl/ossl_asn1.c |
Preserves wider Fixnum values while splitting ASN.1 timestamps. |
ext/openssl/extconf.rb |
Detects the supported OpenSSL time APIs. |
Review effort: Lite
| #ifdef HAVE_SSL_SESSION_SET_TIME_EX | ||
| SSL_SESSION_set_time_ex(ctx, NUM2TIMET(time_v)); | ||
| #else | ||
| SSL_SESSION_set_time(ctx, NUM2LONG(time_v)); |
2807197 to
b4c9e7e
Compare
b4c9e7e to
daca9e2
Compare
rhenium
left a comment
There was a problem hiding this comment.
Thanks for catching this! I've added minor comments inline.
|
|
||
| # added in 3.3.0 | ||
| have_func("SSL_SESSION_get_time_ex(NULL)", ssl_h) | ||
| have_func("SSL_SESSION_set_time_ex(NULL, (time_t)0)", ssl_h) |
There was a problem hiding this comment.
I'd prefer reusing one of them to save a little time since I wouldn't expect LibreSSL and AWS-LC to add them separately.
|
|
||
| if (FIXNUM_P(num)) { | ||
| time_t t = FIX2LONG(num); | ||
| rb_len_t t = FIX2LEN(num); |
There was a problem hiding this comment.
The assumption here was that long can safely be cast to time_t.
Ruby 4.2(?) might change Fixnum to become pointer-sized, but then rb_long2int() called below will also need to be updated at that point. I doubt it'll also use rb_len_t.
(Perhaps it's useful to add FIX2INTPTR() and rb_intptr2int() to Ruby's public headers in advance?)


NUM2TIMETfortime_t, andFIX2LENfor Fixnum values that are not limited totime_t._exversions fortime_t, if available.