libmicrohttpd

HTTP/1.x server C library (MHD 1.x, stable)
Log | Files | Refs | Submodules | README | LICENSE

commit 805182fb262d39802c3af2a79a1d39c0d5dd69fb
parent d3a1aa3b452a844f4fe51b5d949619575346bf99
Author: Christian Grothoff <christian@grothoff.org>
Date:   Tue, 14 Feb 2017 16:22:24 +0100

avoid races with application upon connection upgrade: update state/response before calling MHD_response_execute_upgrade_

Diffstat:
Msrc/microhttpd/connection.c | 18++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c @@ -3005,10 +3005,14 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) #ifdef UPGRADE_SUPPORT if (NULL != connection->response->upgrade_handler) { + struct MHD_Response *resp_clr = connection->response; + socket_start_normal_buffering (connection); + connection->state = MHD_CONNECTION_UPGRADE; + connection->response = NULL; /* This connection is "upgraded". Pass socket to application. */ if (MHD_YES != - MHD_response_execute_upgrade_ (connection->response, + MHD_response_execute_upgrade_ (resp_clr, connection)) { /* upgrade failed, fail hard */ @@ -3016,15 +3020,9 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) NULL); continue; } - connection->state = MHD_CONNECTION_UPGRADE; - /* Response is not required anymore for this conectnion. */ - if (NULL != connection->response) - { - struct MHD_Response *resp_clr = connection->response; - - connection->response = NULL; - MHD_destroy_response (resp_clr); - } + /* Response is not required anymore for this connection. */ + if (NULL != resp_clr) + MHD_destroy_response (resp_clr); continue; } #endif /* UPGRADE_SUPPORT */