QUIC APL: Change SSL_get_event_timeout API design
authorHugo Landau <hlandau@openssl.org>
Wed, 3 May 2023 18:09:05 +0000 (19:09 +0100)
committerTomas Mraz <tomas@openssl.org>
Mon, 29 May 2023 06:51:12 +0000 (08:51 +0200)
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/20879)

include/internal/quic_ssl.h
include/openssl/ssl.h.in
ssl/quic/quic_impl.c
ssl/ssl_lib.c

index f3527dbf9584a2b305e95808bf994d1646fa1098..f8469c4fa74b8094f450f02bb2e788edfe2d1980 100644 (file)
@@ -46,7 +46,8 @@ void ossl_quic_set_accept_state(SSL *s);
 
 __owur int ossl_quic_has_pending(const SSL *s);
 __owur int ossl_quic_handle_events(SSL *s);
-__owur int ossl_quic_get_event_timeout(SSL *s, struct timeval *tv);
+__owur int ossl_quic_get_event_timeout(SSL *s, struct timeval *tv,
+                                       int *is_infinite);
 OSSL_TIME ossl_quic_get_event_deadline(SSL *s);
 __owur int ossl_quic_get_rpoll_descriptor(SSL *s, BIO_POLL_DESCRIPTOR *d);
 __owur int ossl_quic_get_wpoll_descriptor(SSL *s, BIO_POLL_DESCRIPTOR *d);
index dbfd0317ae46b048f9a1aa1999b53b835154d2f6..d580c8f19f0dbf22471b925ef7fde95f008a6809 100644 (file)
@@ -2258,7 +2258,7 @@ size_t SSL_CTX_get_num_tickets(const SSL_CTX *ctx);
 
 /* QUIC support */
 int SSL_handle_events(SSL *s);
-__owur int SSL_get_event_timeout(SSL *s, struct timeval *tv);
+__owur int SSL_get_event_timeout(SSL *s, struct timeval *tv, int *is_infinite);
 __owur int SSL_get_rpoll_descriptor(SSL *s, BIO_POLL_DESCRIPTOR *desc);
 __owur int SSL_get_wpoll_descriptor(SSL *s, BIO_POLL_DESCRIPTOR *desc);
 __owur int SSL_net_read_desired(SSL *s);
index 3297c93d5857561dcc0229d4af08057b4a81696d..8f319ec977303844813f8fbb08a738762dceba55 100644 (file)
@@ -857,11 +857,11 @@ int ossl_quic_handle_events(SSL *s)
 /*
  * SSL_get_event_timeout. Get the time in milliseconds until the SSL object
  * should be ticked by the application by calling SSL_handle_events(). tv is set
- * to 0 if the object should be ticked immediately and tv->tv_sec is set to -1
- * if no timeout is currently active.
+ * to 0 if the object should be ticked immediately. If no timeout is currently
+ * active, *is_infinite is set to 1 and the value of *tv is undefined.
  */
 QUIC_TAKES_LOCK
-int ossl_quic_get_event_timeout(SSL *s, struct timeval *tv)
+int ossl_quic_get_event_timeout(SSL *s, struct timeval *tv, int *is_infinite)
 {
     QCTX ctx;
     OSSL_TIME deadline = ossl_time_infinite();
@@ -875,13 +875,21 @@ int ossl_quic_get_event_timeout(SSL *s, struct timeval *tv)
         = ossl_quic_reactor_get_tick_deadline(ossl_quic_channel_get_reactor(ctx.qc->ch));
 
     if (ossl_time_is_infinite(deadline)) {
-        tv->tv_sec  = -1;
+        *is_infinite = 1;
+
+        /*
+         * Robustness against faulty applications that don't check *is_infinite;
+         * harmless long timeout.
+         */
+        tv->tv_sec  = 1000000;
         tv->tv_usec = 0;
+
         quic_unlock(ctx.qc);
         return 1;
     }
 
     *tv = ossl_time_to_timeval(ossl_time_subtract(deadline, ossl_time_now()));
+    *is_infinite = 0;
     quic_unlock(ctx.qc);
     return 1;
 }
index a29cb3e2c5894bfc1662292bea1cdbcdf1753b02..6848dbad7ae25137da7e9d4bbc9aaeab4be9a4ff 100644 (file)
@@ -7148,22 +7148,25 @@ int SSL_handle_events(SSL *s)
     return 1;
 }
 
-int SSL_get_event_timeout(SSL *s, struct timeval *tv)
+int SSL_get_event_timeout(SSL *s, struct timeval *tv, int *is_infinite)
 {
     SSL_CONNECTION *sc;
 
 #ifndef OPENSSL_NO_QUIC
     if (IS_QUIC(s))
-        return ossl_quic_get_event_timeout(s, tv);
+        return ossl_quic_get_event_timeout(s, tv, is_infinite);
 #endif
 
     sc = SSL_CONNECTION_FROM_SSL_ONLY(s);
     if (sc != NULL && SSL_CONNECTION_IS_DTLS(sc)
-        && DTLSv1_get_timeout(s, tv))
+        && DTLSv1_get_timeout(s, tv)) {
+        *is_infinite = 0;
         return 1;
+    }
 
-    tv->tv_sec  = -1;
+    tv->tv_sec  = 1000000;
     tv->tv_usec = 0;
+    *is_infinite = 1;
     return 1;
 }