From 560470b5d97ea5f122d53d1b85e9f384f8ba9023 Mon Sep 17 00:00:00 2001 From: Matt Caswell Date: Mon, 13 Mar 2023 14:42:50 +0000 Subject: [PATCH] Fix SSL_has_pending() for QUIC connections Reviewed-by: Tomas Mraz Reviewed-by: Paul Dale (Merged from https://github.com/openssl/openssl/pull/20514) --- include/internal/quic_ssl.h | 1 + ssl/quic/quic_impl.c | 15 +++++++++++++-- ssl/ssl_lib.c | 11 ++++++++++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/include/internal/quic_ssl.h b/include/internal/quic_ssl.h index 8846877a4a2..7b89534c22e 100644 --- a/include/internal/quic_ssl.h +++ b/include/internal/quic_ssl.h @@ -43,6 +43,7 @@ int ossl_quic_do_handshake(QUIC_CONNECTION *qc); void ossl_quic_set_connect_state(QUIC_CONNECTION *qc); void ossl_quic_set_accept_state(QUIC_CONNECTION *qc); +__owur int ossl_quic_has_pending(const QUIC_CONNECTION *qc); __owur int ossl_quic_tick(QUIC_CONNECTION *qc); __owur int ossl_quic_get_tick_timeout(QUIC_CONNECTION *qc, struct timeval *tv); __owur int ossl_quic_get_rpoll_descriptor(QUIC_CONNECTION *qc, BIO_POLL_DESCRIPTOR *d); diff --git a/ssl/quic/quic_impl.c b/ssl/quic/quic_impl.c index 48e1cf7c0ef..ba6a863e38f 100644 --- a/ssl/quic/quic_impl.c +++ b/ssl/quic/quic_impl.c @@ -1194,9 +1194,8 @@ int ossl_quic_peek(SSL *s, void *buf, size_t len, size_t *bytes_read) * SSL_pending * ----------- */ -size_t ossl_quic_pending(const SSL *s) +static size_t ossl_quic_pending_int(const QUIC_CONNECTION *qc) { - const QUIC_CONNECTION *qc = QUIC_CONNECTION_FROM_CONST_SSL(s); size_t avail = 0; int fin = 0; @@ -1213,6 +1212,18 @@ size_t ossl_quic_pending(const SSL *s) return avail; } +size_t ossl_quic_pending(const SSL *s) +{ + const QUIC_CONNECTION *qc = QUIC_CONNECTION_FROM_CONST_SSL(s); + + return ossl_quic_pending_int(qc); +} + +int ossl_quic_has_pending(const QUIC_CONNECTION *qc) +{ + return ossl_quic_pending_int(qc) > 0; +} + /* * SSL_stream_conclude * ------------------- diff --git a/ssl/ssl_lib.c b/ssl/ssl_lib.c index 1b2c527eb0a..83510b367a7 100644 --- a/ssl/ssl_lib.c +++ b/ssl/ssl_lib.c @@ -1829,7 +1829,16 @@ int SSL_has_pending(const SSL *s) * That data may not result in any application data, or we may fail to parse * the records for some reason. */ - const SSL_CONNECTION *sc = SSL_CONNECTION_FROM_CONST_SSL(s); + const SSL_CONNECTION *sc; +#ifndef OPENSSL_NO_QUIC + const QUIC_CONNECTION *qc = QUIC_CONNECTION_FROM_CONST_SSL(s); + + if (qc != NULL) + return ossl_quic_has_pending(qc); +#endif + + + sc = SSL_CONNECTION_FROM_CONST_SSL(s); /* Check buffered app data if any first */ if (SSL_CONNECTION_IS_DTLS(sc)) { -- 2.47.2