From 797509fc1105fc54aaeb06bf2c363c31011098d6 Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Sun, 31 Dec 2023 03:05:52 +0000 Subject: [PATCH] Fix a crash processing TLS while a session is closing. git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4715 ed5197a5-7fde-0310-b194-c3ffbd925b24 --- src/http.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/http.c b/src/http.c index 803ef27e..2d054251 100644 --- a/src/http.c +++ b/src/http.c @@ -712,7 +712,7 @@ static void _http_tls_update(tf_http_connection_t* connection) { again = false; - if (connection->is_handshaking) + if (connection->is_handshaking && connection->tls) { switch (tf_tls_session_handshake(connection->tls)) { @@ -727,19 +727,27 @@ static void _http_tls_update(tf_http_connection_t* connection) } } - char buffer[8192]; - int r = tf_tls_session_read_encrypted(connection->tls, buffer, sizeof(buffer)); - if (r > 0) + /* Maybe we became disconnected and cleaned up our TLS session. */ + if (connection->tls) { - _http_write_internal(connection, buffer, r); - again = true; + char buffer[8192]; + int r = tf_tls_session_read_encrypted(connection->tls, buffer, sizeof(buffer)); + if (r > 0) + { + _http_write_internal(connection, buffer, r); + again = true; + } } - r = tf_tls_session_read_plain(connection->tls, buffer, sizeof(buffer)); - if (r > 0) + if (connection->tls) { - _http_on_read_plain(connection, buffer, r); - again = true; + char buffer[8192]; + int r = tf_tls_session_read_plain(connection->tls, buffer, sizeof(buffer)); + if (r > 0) + { + _http_on_read_plain(connection, buffer, r); + again = true; + } } } }