gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libmicrohttpd] branch master updated (ec981dfe -> da42f22c)


From: gnunet
Subject: [libmicrohttpd] branch master updated (ec981dfe -> da42f22c)
Date: Fri, 31 Mar 2023 09:22:46 +0200

This is an automated email from the git hooks/post-receive script.

karlson2k pushed a change to branch master
in repository libmicrohttpd.

    from ec981dfe Bumped version as it should be later then the hotfix release
     new 3c2210e6 ChangeLog: corrected
     new 27ecf2e1 microhttpd.h: fixed typo in doxy
     new 6b5e509f Upgraded TLS: fixed inefficient communication
     new db659970 connection.c: cosmetics
     new 05b59a01 Upgraded connection: replaced two checks with asserts
     new da42f22c Upgraded TLS: use more available memory for pumping the data

The 6 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 ChangeLog                   |   2 +-
 src/include/microhttpd.h    |   2 +-
 src/microhttpd/connection.c |   1 +
 src/microhttpd/response.c   | 118 ++++++++++++++++++++++++++------------------
 4 files changed, 73 insertions(+), 50 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 20262211..3caf7105 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,5 @@
 Web 29 Mar 2023 20:56:00 CEST
-    Bumped version as hotfix was released based on the separate branch. -EG
+    Bumped version as the hotfix was released based on the separate branch. -EG
 
 Sun Feb 26 05:49:30 PM CET 2023
     Fix potential DoS vector in MHD_PostProcessor discovered
diff --git a/src/include/microhttpd.h b/src/include/microhttpd.h
index f3c25177..64cb8509 100644
--- a/src/include/microhttpd.h
+++ b/src/include/microhttpd.h
@@ -6036,7 +6036,7 @@ enum MHD_FEATURE
   /**
    * Get whether IPv6 without IPv4 is supported. If not supported
    * then IPv4 is always enabled in IPv6 sockets and
-   * flag #MHD_USE_DUAL_STACK if always used when #MHD_USE_IPv6 is
+   * flag #MHD_USE_DUAL_STACK is always used when #MHD_USE_IPv6 is
    * specified.
    */
   MHD_FEATURE_IPv6_ONLY = 5,
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index a154da45..f378334c 100644
--- a/src/microhttpd/connection.c
+++ b/src/microhttpd/connection.c
@@ -5121,6 +5121,7 @@ MHD_connection_handle_idle (struct MHD_Connection 
*connection)
           continue;
         }
         /* Response is not required anymore for this connection. */
+        if (1)
         {
           struct MHD_Response *const resp = connection->rp.response;
 
diff --git a/src/microhttpd/response.c b/src/microhttpd/response.c
index f0ca7825..159c8ecb 100644
--- a/src/microhttpd/response.c
+++ b/src/microhttpd/response.c
@@ -1942,22 +1942,14 @@ MHD_response_execute_upgrade_ (struct MHD_Response 
*response,
                MHD_thread_ID_match_current_ (connection->pid) );
 #endif /* MHD_USE_THREADS */
 
-  if (0 == (daemon->options & MHD_ALLOW_UPGRADE))
-    return MHD_NO;
-
-  if (NULL ==
-      MHD_get_response_element_n_ (response, MHD_HEADER_KIND,
-                                   MHD_HTTP_HEADER_UPGRADE,
-                                   MHD_STATICSTR_LEN_ ( \
-                                     MHD_HTTP_HEADER_UPGRADE)))
-  {
-#ifdef HAVE_MESSAGES
-    MHD_DLOG (daemon,
-              _ ("Invalid response for upgrade: " \
-                 "application failed to set the 'Upgrade' header!\n"));
-#endif
-    return MHD_NO;
-  }
+  /* "Upgrade" responses accepted only if MHD_ALLOW_UPGRADE is enabled */
+  mhd_assert (0 != (daemon->options & MHD_ALLOW_UPGRADE));
+  /* The header was checked when response queued */
+  mhd_assert (NULL != \
+              MHD_get_response_element_n_ (response, MHD_HEADER_KIND,
+                                           MHD_HTTP_HEADER_UPGRADE,
+                                           MHD_STATICSTR_LEN_ ( \
+                                             MHD_HTTP_HEADER_UPGRADE)));
 
   urh = MHD_calloc_ (1, sizeof (struct MHD_UpgradeResponseHandle));
   if (NULL == urh)
@@ -1970,9 +1962,6 @@ MHD_response_execute_upgrade_ (struct MHD_Response 
*response,
 #ifdef HTTPS_SUPPORT
   if (0 != (daemon->options & MHD_USE_TLS) )
   {
-    struct MemoryPool *pool;
-    size_t avail;
-    char *buf;
     MHD_socket sv[2];
 #if defined(MHD_socket_nosignal_) || ! defined(MHD_socket_pair_nblk_)
     int res1;
@@ -2051,35 +2040,6 @@ MHD_response_execute_upgrade_ (struct MHD_Response 
*response,
     urh->mhd.socket = sv[1];
     urh->mhd.urh = urh;
     urh->mhd.celi = MHD_EPOLL_STATE_UNREADY;
-    pool = connection->pool;
-    avail = MHD_pool_get_free (pool);
-    if (avail < RESERVE_EBUF_SIZE)
-    {
-      /* connection's pool is totally at the limit,
-         use our 'emergency' buffer of #RESERVE_EBUF_SIZE bytes. */
-      avail = RESERVE_EBUF_SIZE;
-      buf = urh->e_buf;
-#ifdef HAVE_MESSAGES
-      MHD_DLOG (daemon,
-                _ ("Memory shortage in connection's memory pool. " \
-                   "The \"upgraded\" communication will be inefficient.\n"));
-#endif
-    }
-    else
-    {
-      /* Normal case: grab all remaining memory from the
-         connection's pool for the IO buffers; the connection
-         certainly won't need it anymore as we've upgraded
-         to another protocol. */
-      buf = MHD_pool_allocate (pool,
-                               avail,
-                               false);
-    }
-    /* use half the buffer for inbound, half for outbound */
-    urh->in_buffer_size = avail / 2;
-    urh->out_buffer_size = avail - urh->in_buffer_size;
-    urh->in_buffer = buf;
-    urh->out_buffer = &buf[urh->in_buffer_size];
 #ifdef EPOLL_SUPPORT
     /* Launch IO processing by the event loop */
     if (0 != (daemon->options & MHD_USE_EPOLL))
@@ -2180,6 +2140,68 @@ MHD_response_execute_upgrade_ (struct MHD_Response 
*response,
                              connection->socket_fd,
 #endif /* ! HTTPS_SUPPORT */
                              urh);
+
+#ifdef HTTPS_SUPPORT
+  if (0 != (daemon->options & MHD_USE_TLS))
+  {
+    struct MemoryPool *const pool = connection->pool;
+    size_t avail;
+    char *buf;
+
+    if (0 != connection->write_buffer_size)
+    {
+      mhd_assert (NULL != connection->write_buffer);
+      /* All data should be sent already */
+      mhd_assert (connection->write_buffer_send_offset == \
+                  connection->write_buffer_append_offset);
+      (void) MHD_pool_reallocate (pool, connection->write_buffer,
+                                  connection->write_buffer_size, 0);
+      connection->write_buffer_append_offset = 0;
+      connection->write_buffer_send_offset = 0;
+      connection->write_buffer_size = 0;
+    }
+    connection->write_buffer = NULL;
+
+    if (0 != connection->read_buffer_size)
+    {
+      mhd_assert (NULL != connection->read_buffer);
+      (void) MHD_pool_reallocate (pool, connection->read_buffer,
+                                  connection->read_buffer_size, 0);
+      connection->read_buffer_offset = 0;
+      connection->read_buffer_size = 0;
+    }
+    connection->read_buffer = NULL;
+
+    avail = MHD_pool_get_free (pool);
+    if (avail < RESERVE_EBUF_SIZE)
+    {
+      /* connection's pool is totally at the limit,
+         use our 'emergency' buffer of #RESERVE_EBUF_SIZE bytes. */
+      avail = RESERVE_EBUF_SIZE;
+      buf = urh->e_buf;
+#ifdef HAVE_MESSAGES
+      MHD_DLOG (daemon,
+                _ ("Memory shortage in connection's memory pool. " \
+                   "The \"upgraded\" communication will be inefficient.\n"));
+#endif
+    }
+    else
+    {
+      /* Normal case: grab all remaining memory from the
+         connection's pool for the IO buffers; the connection
+         certainly won't need it anymore as we've upgraded
+         to another protocol. */
+      buf = MHD_pool_allocate (pool,
+                               avail,
+                               false);
+    }
+    /* use half the buffer for inbound, half for outbound */
+    urh->in_buffer_size = avail / 2;
+    urh->out_buffer_size = avail - urh->in_buffer_size;
+    urh->in_buffer = buf;
+    urh->out_buffer = buf + urh->in_buffer_size;
+  }
+#endif /* HTTPS_SUPPORT */
   return MHD_YES;
 }
 

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]