From 723cbe8a73fe3644bb4d8f20d475e57f44955b54 Mon Sep 17 00:00:00 2001 From: Hugo Landau Date: Tue, 18 Apr 2023 19:30:55 +0100 Subject: QUIC CHANNEL: Do not copy terminate cause as it is not modified after termination Reviewed-by: Matt Caswell Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/20765) --- include/internal/quic_channel.h | 3 ++- include/internal/quic_tserver.h | 3 ++- ssl/quic/quic_channel.c | 5 +++-- ssl/quic/quic_tserver.c | 3 ++- test/helpers/quictestlib.c | 7 ++++--- 5 files changed, 13 insertions(+), 8 deletions(-) diff --git a/include/internal/quic_channel.h b/include/internal/quic_channel.h index 32e5a57fd9..a33416fd2b 100644 --- a/include/internal/quic_channel.h +++ b/include/internal/quic_channel.h @@ -257,7 +257,8 @@ QUIC_STREAM *ossl_quic_channel_get_stream_by_id(QUIC_CHANNEL *ch, /* Returns 1 if channel is terminating or terminated. */ int ossl_quic_channel_is_term_any(const QUIC_CHANNEL *ch); -QUIC_TERMINATE_CAUSE ossl_quic_channel_get_terminate_cause(const QUIC_CHANNEL *ch); +const QUIC_TERMINATE_CAUSE * +ossl_quic_channel_get_terminate_cause(const QUIC_CHANNEL *ch); int ossl_quic_channel_is_terminating(const QUIC_CHANNEL *ch); int ossl_quic_channel_is_terminated(const QUIC_CHANNEL *ch); int ossl_quic_channel_is_active(const QUIC_CHANNEL *ch); diff --git a/include/internal/quic_tserver.h b/include/internal/quic_tserver.h index fd657049ab..89879b01b7 100644 --- a/include/internal/quic_tserver.h +++ b/include/internal/quic_tserver.h @@ -71,7 +71,8 @@ int ossl_quic_tserver_is_handshake_confirmed(const QUIC_TSERVER *srv); /* Returns 1 if the server is in any terminating or terminated state */ int ossl_quic_tserver_is_term_any(const QUIC_TSERVER *srv); -QUIC_TERMINATE_CAUSE ossl_quic_tserver_get_terminate_cause(const QUIC_TSERVER *srv); +const QUIC_TERMINATE_CAUSE * +ossl_quic_tserver_get_terminate_cause(const QUIC_TSERVER *srv); /* Returns 1 if the server is in a terminated state */ int ossl_quic_tserver_is_terminated(const QUIC_TSERVER *srv); diff --git a/ssl/quic/quic_channel.c b/ssl/quic/quic_channel.c index c689166805..da2436b3c6 100644 --- a/ssl/quic/quic_channel.c +++ b/ssl/quic/quic_channel.c @@ -445,9 +445,10 @@ int ossl_quic_channel_is_term_any(const QUIC_CHANNEL *ch) || ossl_quic_channel_is_terminated(ch); } -QUIC_TERMINATE_CAUSE ossl_quic_channel_get_terminate_cause(const QUIC_CHANNEL *ch) +const QUIC_TERMINATE_CAUSE * +ossl_quic_channel_get_terminate_cause(const QUIC_CHANNEL *ch) { - return ch->terminate_cause; + return ossl_quic_channel_is_term_any(ch) ? &ch->terminate_cause : NULL; } int ossl_quic_channel_is_handshake_complete(const QUIC_CHANNEL *ch) diff --git a/ssl/quic/quic_tserver.c b/ssl/quic/quic_tserver.c index 12f4516608..17b70eb3a5 100644 --- a/ssl/quic/quic_tserver.c +++ b/ssl/quic/quic_tserver.c @@ -169,7 +169,8 @@ int ossl_quic_tserver_is_term_any(const QUIC_TSERVER *srv) return ossl_quic_channel_is_term_any(srv->ch); } -QUIC_TERMINATE_CAUSE ossl_quic_tserver_get_terminate_cause(const QUIC_TSERVER *srv) +const QUIC_TERMINATE_CAUSE * +ossl_quic_tserver_get_terminate_cause(const QUIC_TSERVER *srv) { return ossl_quic_channel_get_terminate_cause(srv->ch); } diff --git a/test/helpers/quictestlib.c b/test/helpers/quictestlib.c index e60573eb6e..c973a8cc65 100644 --- a/test/helpers/quictestlib.c +++ b/test/helpers/quictestlib.c @@ -312,7 +312,7 @@ int qtest_shutdown(QUIC_TSERVER *qtserv, SSL *clientssl) int qtest_check_server_transport_err(QUIC_TSERVER *qtserv, uint64_t code) { - QUIC_TERMINATE_CAUSE cause; + const QUIC_TERMINATE_CAUSE *cause; ossl_quic_tserver_tick(qtserv); @@ -323,8 +323,9 @@ int qtest_check_server_transport_err(QUIC_TSERVER *qtserv, uint64_t code) return 0; cause = ossl_quic_tserver_get_terminate_cause(qtserv); - if (!TEST_true(cause.remote) - || !TEST_uint64_t_eq(cause.error_code, code)) + if (!TEST_ptr(cause) + || !TEST_true(cause->remote) + || !TEST_uint64_t_eq(cause->error_code, code)) return 0; return 1; -- cgit v1.2.1