gnunet-svn
[Top][All Lists]
Advanced

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

[libmicrohttpd] branch master updated (d929a447 -> e9fbb331)


From: gnunet
Subject: [libmicrohttpd] branch master updated (d929a447 -> e9fbb331)
Date: Wed, 11 Aug 2021 21:37:02 +0200

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

karlson2k pushed a change to branch master
in repository libmicrohttpd.

    from d929a447 -typo
     new dd9c7075 MHD_queue_response(): detect incorrect "upgrade" responses
     new 88da9c6f internal.h: minor doxy correction
     new af3fc639 response headers: do not allow "Close" with upgrade responses
     new 96a0da03 response.c: used stricter check for "Upgrade:" header
     new e9fbb331 connection.c: cosmetics

The 5 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:
 src/microhttpd/connection.c | 65 +++++++++++++++++++++++++++++++++++----------
 src/microhttpd/internal.h   |  2 +-
 src/microhttpd/response.c   | 17 +++++++++---
 3 files changed, 65 insertions(+), 19 deletions(-)

diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index b2d285e3..f9852a06 100644
--- a/src/microhttpd/connection.c
+++ b/src/microhttpd/connection.c
@@ -1389,7 +1389,9 @@ connection_shrink_read_buffer (struct MHD_Connection 
*connection)
   new_buf = MHD_pool_reallocate (c->pool, c->read_buffer, c->read_buffer_size,
                                  c->read_buffer_offset);
   mhd_assert (c->read_buffer == new_buf);
+#ifdef NDEBUG
   (void) new_buf; /* squash compiler warning */
+#endif /* NDEBUG */
   c->read_buffer_size = c->read_buffer_offset;
   if (0 == c->read_buffer_size)
     c->read_buffer = NULL;
@@ -4564,25 +4566,60 @@ MHD_queue_response (struct MHD_Connection *connection,
     return MHD_NO;
 
 #ifdef UPGRADE_SUPPORT
-  if ( (NULL != response->upgrade_handler) &&
-       (0 == (daemon->options & MHD_ALLOW_UPGRADE)) )
+  if (NULL != response->upgrade_handler)
   {
+    struct MHD_HTTP_Header *conn_header;
+    if (0 == (daemon->options & MHD_ALLOW_UPGRADE))
+    {
 #ifdef HAVE_MESSAGES
-    MHD_DLOG (daemon,
-              _ (
-                "Attempted 'upgrade' connection on daemon without 
MHD_ALLOW_UPGRADE option!\n"));
+      MHD_DLOG (daemon,
+                _ ("Attempted 'upgrade' connection on daemon without" \
+                   " MHD_ALLOW_UPGRADE option!\n"));
 #endif
-    return MHD_NO;
-  }
-  if ( (MHD_HTTP_SWITCHING_PROTOCOLS != status_code) &&
-       (NULL != response->upgrade_handler) )
-  {
+      return MHD_NO;
+    }
+    if (MHD_HTTP_SWITCHING_PROTOCOLS != status_code)
+    {
 #ifdef HAVE_MESSAGES
-    MHD_DLOG (daemon,
-              _ (
-                "Application used invalid status code for 'upgrade' 
response!\n"));
+      MHD_DLOG (daemon,
+                _ ("Application used invalid status code for" \
+                   " 'upgrade' response!\n"));
 #endif
-    return MHD_NO;
+      return MHD_NO;
+    }
+    if (0 == (response->flags_auto & MHD_RAF_HAS_CONNECTION_HDR))
+    {
+#ifdef HAVE_MESSAGES
+      MHD_DLOG (daemon,
+                _ ("Application used invalid response" \
+                   " without \"Connection\" header!\n"));
+#endif
+      return MHD_NO;
+    }
+    conn_header = response->first_header;
+    mhd_assert (NULL != conn_header);
+    mhd_assert (MHD_str_equal_caseless_ (conn_header->header,
+                                         MHD_HTTP_HEADER_CONNECTION));
+    if (! MHD_str_has_s_token_caseless_ (conn_header->value,
+                                         "upgrade"))
+    {
+#ifdef HAVE_MESSAGES
+      MHD_DLOG (daemon,
+                _ ("Application used invalid response" \
+                   " without \"upgrade\" token in" \
+                   " \"Connection\" header!\n"));
+#endif
+      return MHD_NO;
+    }
+    if (! MHD_IS_HTTP_VER_1_1_COMPAT (connection->http_ver))
+    {
+#ifdef HAVE_MESSAGES
+      MHD_DLOG (daemon,
+                _ ("Connection \"Upgrade\" can be used " \
+                   "with HTTP/1.1 connections!\n"));
+#endif
+      return MHD_NO;
+    }
   }
 #endif /* UPGRADE_SUPPORT */
   if ( (100 > (status_code & (~MHD_ICY_FLAG))) ||
diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h
index 87e75063..9d23f85e 100644
--- a/src/microhttpd/internal.h
+++ b/src/microhttpd/internal.h
@@ -814,7 +814,7 @@ enum MHD_HTTP_Version
 /**
  * The HTTP method.
  *
- * Only primary methods (specified in RFC7231) defined here.
+ * Only primary methods (specified in RFC7231) are defined here.
  */
 enum MHD_HTTP_Method
 {
diff --git a/src/microhttpd/response.c b/src/microhttpd/response.c
index a7085767..c869afcf 100644
--- a/src/microhttpd/response.c
+++ b/src/microhttpd/response.c
@@ -266,6 +266,13 @@ add_response_header_connection (struct MHD_Response 
*response,
                                                       "close"),
                                                     buf + old_value_len,
                                                     &norm_len);
+#ifdef UPGRADE_SUPPORT
+  if ( (NULL != response->upgrade_handler) && value_has_close)
+  { /* The "close" token cannot be used with connection "upgrade" */
+    free (buf);
+    return MHD_NO;
+  }
+#endif /* UPGRADE_SUPPORT */
   mhd_assert (0 <= norm_len);
   if (0 > norm_len)
     norm_len = 0; /* Must never happen */
@@ -1609,13 +1616,15 @@ MHD_response_execute_upgrade_ (struct MHD_Response 
*response,
     return MHD_NO;
 
   if (NULL ==
-      MHD_get_response_header (response,
-                               MHD_HTTP_HEADER_UPGRADE))
+      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"));
+              _ ("Invalid response for upgrade: " \
+                 "application failed to set the 'Upgrade' header!\n"));
 #endif
     return MHD_NO;
   }

-- 
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]