瀏覽代碼

MHD_queue_response(): check for correct thread ID

Evgeny Grin (Karlson2k) 8 年之前
父節點
當前提交
7934cc0777
共有 2 個文件被更改,包括 13 次插入3 次删除
  1. 11 3
      src/microhttpd/connection.c
  2. 2 0
      src/microhttpd/daemon.c

+ 11 - 3
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)) )
     {

+ 2 - 0
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))
     {