From 5385264f949dd746eeba33a5b660b48437111dd5 Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Mon, 25 Mar 2024 16:31:09 -0400 Subject: [PATCH] Fix an http use after free during shutdown. --- src/http.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/http.c b/src/http.c index c4a67319..f5d2a16f 100644 --- a/src/http.c +++ b/src/http.c @@ -381,11 +381,19 @@ static void _http_add_body_bytes(tf_http_connection_t* connection, const void* d }; connection->request = request; - tf_http_request_ref(request); - tf_trace_begin(connection->http->trace, connection->trace_name ? connection->trace_name : "http"); - connection->callback(request); - tf_trace_end(connection->http->trace); - tf_http_request_unref(request); + if (!connection->http->is_shutting_down) + { + tf_http_request_ref(request); + tf_trace_begin(connection->http->trace, connection->trace_name ? connection->trace_name : "http"); + connection->callback(request); + tf_trace_end(connection->http->trace); + tf_http_request_unref(request); + } + else + { + const char* k_payload = tf_http_status_text(503); + tf_http_respond(request, 503, NULL, 0, k_payload, strlen(k_payload)); + } } } } @@ -784,6 +792,8 @@ const char* tf_http_status_text(int status) return "File not found"; case 500: return "Internal server error"; + case 503: + return "Service Unavailable"; default: return "Unknown"; }