libmicrohttpd

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

commit 7934cc0777f86151b630e54f182c04015b9f488d
parent 953942677b185da6bf5a66adbf968446dd901841
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date:   Sun, 27 Aug 2017 21:44:40 +0300

MHD_queue_response(): check for correct thread ID

Diffstat:
Msrc/microhttpd/connection.c | 14+++++++++++---
Msrc/microhttpd/daemon.c | 2++
2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c @@ -3769,9 +3769,7 @@ MHD_queue_response (struct MHD_Connection *connection, unsigned int status_code, struct MHD_Response *response) { -#ifdef UPGRADE_SUPPORT struct MHD_Daemon *daemon; -#endif /* UPGRADE_SUPPORT */ if ( (NULL == connection) || (NULL == response) || @@ -3779,8 +3777,18 @@ MHD_queue_response (struct MHD_Connection *connection, ( (MHD_CONNECTION_HEADERS_PROCESSED != connection->state) && (MHD_CONNECTION_FOOTERS_RECEIVED != connection->state) ) ) return MHD_NO; -#ifdef UPGRADE_SUPPORT daemon = connection->daemon; + if ( (!connection->suspended) && + (0 != (daemon->options & MHD_USE_INTERNAL_POLLING_THREAD)) && + (!MHD_thread_ID_match_current_(connection->pid.ID)) ) + { +#ifdef HAVE_MESSAGES + MHD_DLOG (daemon, + _("Attempted to queue response on wrong thread!\n")); +#endif + return MHD_NO; + } +#ifdef UPGRADE_SUPPORT if ( (NULL != response->upgrade_handler) && (0 == (daemon->options & MHD_ALLOW_UPGRADE)) ) { diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c @@ -2397,6 +2397,8 @@ internal_add_connection (struct MHD_Daemon *daemon, goto cleanup; } } + else + connection->pid = daemon->pid; #ifdef EPOLL_SUPPORT if (0 != (daemon->options & MHD_USE_EPOLL)) {