diff options
author | Christian Grothoff <christian@grothoff.org> | 2017-02-14 16:22:24 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2017-02-14 16:22:24 +0100 |
commit | 805182fb262d39802c3af2a79a1d39c0d5dd69fb (patch) | |
tree | b80d3810321c2827c2376e35b961f1de5be2c63d | |
parent | d3a1aa3b452a844f4fe51b5d949619575346bf99 (diff) | |
download | libmicrohttpd-805182fb262d39802c3af2a79a1d39c0d5dd69fb.tar.gz libmicrohttpd-805182fb262d39802c3af2a79a1d39c0d5dd69fb.zip |
avoid races with application upon connection upgrade: update state/response before calling MHD_response_execute_upgrade_
-rw-r--r-- | src/microhttpd/connection.c | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c index ef596dad..af5fac78 100644 --- a/src/microhttpd/connection.c +++ b/src/microhttpd/connection.c | |||
@@ -3005,10 +3005,14 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) | |||
3005 | #ifdef UPGRADE_SUPPORT | 3005 | #ifdef UPGRADE_SUPPORT |
3006 | if (NULL != connection->response->upgrade_handler) | 3006 | if (NULL != connection->response->upgrade_handler) |
3007 | { | 3007 | { |
3008 | struct MHD_Response *resp_clr = connection->response; | ||
3009 | |||
3008 | socket_start_normal_buffering (connection); | 3010 | socket_start_normal_buffering (connection); |
3011 | connection->state = MHD_CONNECTION_UPGRADE; | ||
3012 | connection->response = NULL; | ||
3009 | /* This connection is "upgraded". Pass socket to application. */ | 3013 | /* This connection is "upgraded". Pass socket to application. */ |
3010 | if (MHD_YES != | 3014 | if (MHD_YES != |
3011 | MHD_response_execute_upgrade_ (connection->response, | 3015 | MHD_response_execute_upgrade_ (resp_clr, |
3012 | connection)) | 3016 | connection)) |
3013 | { | 3017 | { |
3014 | /* upgrade failed, fail hard */ | 3018 | /* upgrade failed, fail hard */ |
@@ -3016,15 +3020,9 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) | |||
3016 | NULL); | 3020 | NULL); |
3017 | continue; | 3021 | continue; |
3018 | } | 3022 | } |
3019 | connection->state = MHD_CONNECTION_UPGRADE; | 3023 | /* Response is not required anymore for this connection. */ |
3020 | /* Response is not required anymore for this conectnion. */ | 3024 | if (NULL != resp_clr) |
3021 | if (NULL != connection->response) | 3025 | MHD_destroy_response (resp_clr); |
3022 | { | ||
3023 | struct MHD_Response *resp_clr = connection->response; | ||
3024 | |||
3025 | connection->response = NULL; | ||
3026 | MHD_destroy_response (resp_clr); | ||
3027 | } | ||
3028 | continue; | 3026 | continue; |
3029 | } | 3027 | } |
3030 | #endif /* UPGRADE_SUPPORT */ | 3028 | #endif /* UPGRADE_SUPPORT */ |