gnunet-svn
[Top][All Lists]
Advanced

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

[libmicrohttpd] branch master updated (746dae6a -> 381f2705)


From: gnunet
Subject: [libmicrohttpd] branch master updated (746dae6a -> 381f2705)
Date: Sun, 17 Oct 2021 16:31:53 +0200

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

karlson2k pushed a change to branch master
in repository libmicrohttpd.

    from 746dae6a Added error response for wrong 'Content-Length' values
     new 17d613d9 get_next_header_line(): improved and fixed comments
     new 0c39b804 Removed leftover after 
3a02f18ca6a66997614cebf1231c86ad33148ad2
     new 4ad019fd Fixed parsing of bare CR as end-of-line in HTTP headers
     new 44b342f7 internal.h: fixed doxy for read buffer
     new 381f2705 Fixed parsing of "\r\r", "\r", "\n\r" and "\n\n" as a single 
linefeed for chunked upload

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 | 86 +++++++++++++++++++++++++--------------------
 src/microhttpd/internal.h   | 11 +++---
 2 files changed, 53 insertions(+), 44 deletions(-)

diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index eb161ce7..d524954a 100644
--- a/src/microhttpd/connection.c
+++ b/src/microhttpd/connection.c
@@ -2549,42 +2549,54 @@ get_next_header_line (struct MHD_Connection *connection,
     return NULL;
   pos = 0;
   rbuf = connection->read_buffer;
-  while ( (pos < connection->read_buffer_offset - 1) &&
-          ('\r' != rbuf[pos]) &&
-          ('\n' != rbuf[pos]) )
-    pos++;
-  if ( (pos == connection->read_buffer_offset - 1) &&
-       ('\n' != rbuf[pos]) )
+  mhd_assert (NULL != rbuf);
+
+  do
   {
-    /* not found, consider growing... */
-    if ( (connection->read_buffer_offset == connection->read_buffer_size) &&
-         (! try_grow_read_buffer (connection, true)) )
+    const char c = rbuf[pos];
+    bool found;
+    found = false;
+    if ( ('\r' == c) && (pos < connection->read_buffer_offset - 1) &&
+         ('\n' == rbuf[pos + 1]) )
+    { /* Found CRLF */
+      found = true;
+      if (line_len)
+        *line_len = pos;
+      rbuf[pos++] = 0; /* Replace CR with zero */
+      rbuf[pos++] = 0; /* Replace LF with zero */
+    }
+    else if ('\n' == c) /* TODO: Add MHD option to disallow */
+    { /* Found bare LF */
+      found = true;
+      if (line_len)
+        *line_len = pos;
+      rbuf[pos++] = 0; /* Replace LF with zero */
+    }
+    if (found)
     {
-      if (NULL != connection->url)
-        transmit_error_response_static (connection,
-                                        
MHD_HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE,
-                                        REQUEST_TOO_BIG);
-      else
-        transmit_error_response_static (connection,
-                                        MHD_HTTP_URI_TOO_LONG,
-                                        REQUEST_TOO_BIG);
+      connection->read_buffer += pos;
+      connection->read_buffer_size -= pos;
+      connection->read_buffer_offset -= pos;
+      return rbuf;
     }
-    if (line_len)
-      *line_len = 0;
-    return NULL;
-  }
+  } while (++pos < connection->read_buffer_offset);
 
+  /* not found, consider growing... */
+  if ( (connection->read_buffer_offset == connection->read_buffer_size) &&
+       (! try_grow_read_buffer (connection, true)) )
+  {
+    if (NULL != connection->url)
+      transmit_error_response_static (connection,
+                                      MHD_HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE,
+                                      REQUEST_TOO_BIG);
+    else
+      transmit_error_response_static (connection,
+                                      MHD_HTTP_URI_TOO_LONG,
+                                      REQUEST_TOO_BIG);
+  }
   if (line_len)
-    *line_len = pos;
-  /* found, check if we have proper LFCR */
-  if ( ('\r' == rbuf[pos]) &&
-       ('\n' == rbuf[pos + 1]) )
-    rbuf[pos++] = '\0';         /* skip both r and n */
-  rbuf[pos++] = '\0';
-  connection->read_buffer += pos;
-  connection->read_buffer_size -= pos;
-  connection->read_buffer_offset -= pos;
-  return rbuf;
+    *line_len = 0;
+  return NULL;
 }
 
 
@@ -3084,12 +3096,11 @@ process_request_body (struct MHD_Connection *connection)
         size_t i;
         /* skip new line at the *end* of a chunk */
         i = 0;
-        if ( ('\r' == buffer_head[i]) ||
-             ('\n' == buffer_head[i]) )
-          i++;                  /* skip 1st part of line feed */
-        if ( ('\r' == buffer_head[i]) ||
-             ('\n' == buffer_head[i]) )
-          i++;                  /* skip 2nd part of line feed */
+        if ( ('\r' == buffer_head[i]) &&
+             ('\n' == buffer_head[i + 1]) )
+          i += 2;                        /* skip CRLF */
+        else if ('\n' == buffer_head[i]) /* TODO: Add MHD option to disallow */
+          i++;                           /* skip bare LF */
         if (0 == i)
         {
           /* malformed encoding */
@@ -3456,7 +3467,6 @@ static void
 parse_connection_headers (struct MHD_Connection *connection)
 {
   const char *clen;
-  struct MHD_Response *response;
   const char *enc;
   const char *end;
 
diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h
index ab5d948c..0a6ba032 100644
--- a/src/microhttpd/internal.h
+++ b/src/microhttpd/internal.h
@@ -1072,16 +1072,15 @@ struct MHD_Connection
 #endif
 
   /**
-   * Size of @e read_buffer (in bytes).  This value indicates
-   * how many bytes we're willing to read into the buffer;
-   * the real buffer is one byte longer to allow for
-   * adding zero-termination (when needed).
+   * Size of @e read_buffer (in bytes).
+   * This value indicates how many bytes we're willing to read
+   * into the buffer.
    */
   size_t read_buffer_size;
 
   /**
-   * Position where we currently append data in
-   * @e read_buffer (last valid position).
+   * Position where we currently append data in @e read_buffer (the
+   * next char after the last valid position).
    */
   size_t read_buffer_offset;
 

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