gnunet-svn
[Top][All Lists]
Advanced

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

[libmicrohttpd] branch master updated (c07f4464 -> d7cac578)


From: gnunet
Subject: [libmicrohttpd] branch master updated (c07f4464 -> d7cac578)
Date: Wed, 29 Sep 2021 19:52:42 +0200

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

karlson2k pushed a change to branch master
in repository libmicrohttpd.

    from c07f4464 microhttpd.h: fixed doxy for MHD_KeyValueIteratorN
     new 235a277d connection.c: fixed compile with disabled messages
     new 7278e581 memorypool: added assert in MHD_pool_reallocate()
     new 4e01fd65 connection_close_error(): fixed set of error flag with 
messages disabled
     new cb5332ab transmit_error_response(): avoid double sending of error 
responses
     new ccd75de5 connection_reset(): notify app with correct code
     new 85afdbaf transmit_error_response(): check whether it is still possible 
to send a response
     new f7c12138 transmit_error_response(): log error if response cannot be 
created
     new ac72beaa transmit_error_response(): improved error log messages
     new 0eb37064 transmit_error_response(): reset read buffer offset as well
     new d7cac578 connection_maximize_write_buffer(): don't try to grow if no 
space is available

The 10 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 | 94 +++++++++++++++++++++++++++++++--------------
 src/microhttpd/memorypool.c |  3 ++
 2 files changed, 68 insertions(+), 29 deletions(-)

diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index d1d97e2e..3e6a4ba0 100644
--- a/src/microhttpd/connection.c
+++ b/src/microhttpd/connection.c
@@ -187,6 +187,8 @@ str_conn_error_ (ssize_t mhd_err_code)
 }
 
 
+#endif /* HAVE_MESSAGES */
+
 /**
  * Allocate memory from connection's memory pool.
  * If memory pool doesn't have enough free memory but read of write buffer
@@ -258,8 +260,6 @@ connection_alloc_memory (struct MHD_Connection *connection,
 }
 
 
-#endif /* HAVE_MESSAGES */
-
 /**
  * Callback for receiving data from the socket.
  *
@@ -901,8 +901,8 @@ static void
 connection_close_error (struct MHD_Connection *connection,
                         const char *emsg)
 {
-#ifdef HAVE_MESSAGES
   connection->stop_with_error = true;
+#ifdef HAVE_MESSAGES
   if (NULL != emsg)
     MHD_DLOG (connection->daemon,
               "%s\n",
@@ -1523,27 +1523,32 @@ connection_maximize_write_buffer (struct MHD_Connection 
*connection)
   struct MemoryPool *const pool = connection->pool;
   void *new_buf;
   size_t new_size;
+  size_t free_size;
 
   mhd_assert ((NULL != c->write_buffer) || (0 == c->write_buffer_size));
   mhd_assert (c->write_buffer_append_offset >= c->write_buffer_send_offset);
   mhd_assert (c->write_buffer_size >= c->write_buffer_append_offset);
 
-  new_size = c->write_buffer_size + MHD_pool_get_free (pool);
-  new_buf = MHD_pool_reallocate (pool,
-                                 c->write_buffer,
-                                 c->write_buffer_size,
-                                 new_size);
-  /* Buffer position must not be moved.
-   * Position could be moved only if buffer was allocated 'from_end',
-   * which cannot happen. */
-  mhd_assert ((c->write_buffer == new_buf) || (NULL == c->write_buffer));
-  c->write_buffer = new_buf;
-  c->write_buffer_size = new_size;
-  if (c->write_buffer_send_offset == c->write_buffer_append_offset)
+  free_size = MHD_pool_get_free (pool);
+  if (0 != free_size)
   {
-    /* All data have been sent, reset offsets to zero. */
-    c->write_buffer_send_offset = 0;
-    c->write_buffer_append_offset = 0;
+    new_size = c->write_buffer_size + free_size;
+    new_buf = MHD_pool_reallocate (pool,
+                                   c->write_buffer,
+                                   c->write_buffer_size,
+                                   new_size);
+    /* Buffer position must not be moved.
+     * Position could be moved only if buffer was allocated 'from_end',
+     * which cannot happen. */
+    mhd_assert ((c->write_buffer == new_buf) || (NULL == c->write_buffer));
+    c->write_buffer = new_buf;
+    c->write_buffer_size = new_size;
+    if (c->write_buffer_send_offset == c->write_buffer_append_offset)
+    {
+      /* All data have been sent, reset offsets to zero. */
+      c->write_buffer_send_offset = 0;
+      c->write_buffer_append_offset = 0;
+    }
   }
 
   return c->write_buffer_size - c->write_buffer_append_offset;
@@ -2200,7 +2205,35 @@ transmit_error_response_len (struct MHD_Connection 
*connection,
   struct MHD_Response *response;
   enum MHD_Result iret;
 
+  mhd_assert (! connection->stop_with_error); /* Send error one time only */
+  if (connection->stop_with_error)
+  { /* Should not happen */
+    if (MHD_CONNECTION_CLOSED > connection->state)
+      connection->state = MHD_CONNECTION_CLOSED;
+
+    return;
+  }
   connection->stop_with_error = true;
+#ifdef HAVE_MESSAGES
+  MHD_DLOG (connection->daemon,
+            _ ("Error processing request (HTTP response code is %u ('%s')). " \
+               "Closing connection.\n"),
+            status_code,
+            message);
+#endif
+  if (MHD_CONNECTION_START_REPLY < connection->state)
+  {
+#ifdef HAVE_MESSAGES
+    MHD_DLOG (connection->daemon,
+              _ ("Too late to send an error response, " \
+                 "response is being sent already.\n"),
+              status_code,
+              message);
+#endif
+    CONNECTION_CLOSE_ERROR (connection,
+                            _ ("Too late for error response."));
+    return;
+  }
   /* TODO: remove when special error queue function is implemented */
   connection->state = MHD_CONNECTION_FULL_REQ_RECEIVED;
   if (0 != connection->read_buffer_size)
@@ -2212,14 +2245,8 @@ transmit_error_response_len (struct MHD_Connection 
*connection,
                                                    
connection->read_buffer_size,
                                                    0);
     connection->read_buffer_size = 0;
+    connection->read_buffer_offset = 0;
   }
-#ifdef HAVE_MESSAGES
-  MHD_DLOG (connection->daemon,
-            _ (
-              "Error processing request (HTTP response code is %u (`%s')). 
Closing connection.\n"),
-            status_code,
-            message);
-#endif
   if (NULL != connection->response)
   {
     MHD_destroy_response (connection->response);
@@ -2230,6 +2257,12 @@ transmit_error_response_len (struct MHD_Connection 
*connection,
                                               MHD_RESPMEM_PERSISTENT);
   if (NULL == response)
   {
+#ifdef HAVE_MESSAGES
+    MHD_DLOG (connection->daemon,
+              _ ("Failed to create error response.\n"),
+              status_code,
+              message);
+#endif
     /* can't even send a reply, at least close the connection */
     connection->state = MHD_CONNECTION_CLOSED;
     return;
@@ -2242,8 +2275,8 @@ transmit_error_response_len (struct MHD_Connection 
*connection,
   {
     /* can't even send a reply, at least close the connection */
     CONNECTION_CLOSE_ERROR (connection,
-                            _ (
-                              "Closing connection (failed to queue 
response)."));
+                            _ ("Closing connection " \
+                               "(failed to queue error response)."));
     return;
   }
   mhd_assert (NULL != connection->response);
@@ -2253,8 +2286,8 @@ transmit_error_response_len (struct MHD_Connection 
*connection,
   {
     /* oops - close! */
     CONNECTION_CLOSE_ERROR (connection,
-                            _ (
-                              "Closing connection (failed to create response 
header)."));
+                            _ ("Closing connection " \
+                               "(failed to create error response header)."));
   }
   else
   {
@@ -4070,6 +4103,8 @@ connection_reset (struct MHD_Connection *connection,
     /* Next function will destroy response, notify client,
      * destroy memory pool, and set connection state to "CLOSED" */
     MHD_connection_close_ (connection,
+                           c->stop_with_error ?
+                           MHD_REQUEST_TERMINATED_WITH_ERROR :
                            MHD_REQUEST_TERMINATED_COMPLETED_OK);
     c->read_buffer = NULL;
     c->read_buffer_size = 0;
@@ -4083,6 +4118,7 @@ connection_reset (struct MHD_Connection *connection,
   {
     /* Reset connection to process the next request */
     size_t new_read_buf_size;
+    mhd_assert (! c->stop_with_error);
 
     if ( (NULL != d->notify_completed) &&
          (c->client_aware) )
diff --git a/src/microhttpd/memorypool.c b/src/microhttpd/memorypool.c
index 63181f59..c5e5b4fd 100644
--- a/src/microhttpd/memorypool.c
+++ b/src/microhttpd/memorypool.c
@@ -350,6 +350,9 @@ MHD_pool_reallocate (struct MemoryPool *pool,
   /* (old == NULL || old_size == 0 || pool->memory + pool->pos > (uint8_t*) 
old) */
   mhd_assert (old == NULL || old_size == 0 || \
               pool->pos > (size_t) ((uint8_t*) old - pool->memory));
+  mhd_assert (old == NULL || old_size == 0 || \
+              (size_t) (((uint8_t*) old) - pool->memory) + old_size <= \
+              pool->end);
 
   if (0 != old_size)
   {   /* Need to save some data */

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