gnunet-svn
[Top][All Lists]
Advanced

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

[libmicrohttpd] branch master updated (ce7e1e50 -> 7a6a9d14)


From: gnunet
Subject: [libmicrohttpd] branch master updated (ce7e1e50 -> 7a6a9d14)
Date: Sun, 12 Sep 2021 18:32:21 +0200

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

karlson2k pushed a change to branch master
in repository libmicrohttpd.

    from ce7e1e50 test_postprocessor: catch impossible value
     new bf6be24b test_postprocessor: fixed call of memcmp() with NULL pointers
     new 4017f5a3 postprocessor: added asserts in process_value()
     new 6c2f3cf2 postprocessor: fixed undefined behavior error
     new e7248780 postprocessor: do not call memcpy() / memmove() with zero size
     new 7a6a9d14 postprocessor: minor optimization: do not process zero-length 
data

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/postprocessor.c      | 42 ++++++++++++++++++++++++-------------
 src/microhttpd/test_postprocessor.c | 17 +++++++++++----
 2 files changed, 41 insertions(+), 18 deletions(-)

diff --git a/src/microhttpd/postprocessor.c b/src/microhttpd/postprocessor.c
index 3a19af02..7c78020e 100644
--- a/src/microhttpd/postprocessor.c
+++ b/src/microhttpd/postprocessor.c
@@ -355,10 +355,15 @@ process_value (struct MHD_PostProcessor *pp,
   size_t xoff;
 
   mhd_assert (pp->xbuf_pos < sizeof (xbuf));
+  /* 'value_start' and 'value_end' must be either both non-NULL or both NULL */
+  mhd_assert ( (NULL == value_start) || (NULL != value_end) );
+  mhd_assert ( (NULL != value_start) || (NULL == value_end) );
+  mhd_assert ( (NULL == last_escape) || (NULL != value_start) );
   /* move remaining input from previous round into processing buffer */
-  memcpy (xbuf,
-          pp->xbuf,
-          pp->xbuf_pos);
+  if (0 != pp->xbuf_pos)
+    memcpy (xbuf,
+            pp->xbuf,
+            pp->xbuf_pos);
   xoff = pp->xbuf_pos;
   pp->xbuf_pos = 0;
   if ( (NULL != last_escape) &&
@@ -381,11 +386,14 @@ process_value (struct MHD_PostProcessor *pp,
     if (delta > XBUF_SIZE - xoff)
       delta = XBUF_SIZE - xoff;
     /* move (additional) input into processing buffer */
-    memcpy (&xbuf[xoff],
-            value_start,
-            delta);
-    xoff += delta;
-    value_start += delta;
+    if (0 != delta)
+    {
+      memcpy (&xbuf[xoff],
+              value_start,
+              delta);
+      xoff += delta;
+      value_start += delta;
+    }
     /* find if escape sequence is at the end of the processing buffer;
        if so, exclude those from processing (reduce delta to point at
        end of processed region) */
@@ -430,8 +438,11 @@ process_value (struct MHD_PostProcessor *pp,
     mhd_assert (xoff < sizeof (xbuf));
     /* unescape */
     xbuf[xoff] = '\0';        /* 0-terminate in preparation */
-    MHD_unescape_plus (xbuf);
-    xoff = MHD_http_unescape (xbuf);
+    if (0 != xoff)
+    {
+      MHD_unescape_plus (xbuf);
+      xoff = MHD_http_unescape (xbuf);
+    }
     /* finally: call application! */
     if (pp->must_ikvi || (0 != xoff) )
     {
@@ -453,10 +464,13 @@ process_value (struct MHD_PostProcessor *pp,
     pp->value_offset += xoff;
     if (cut)
       break;
-    xbuf[delta] = '%';        /* undo 0-termination */
-    memmove (xbuf,
-             &xbuf[delta],
-             clen);
+    if (0 != clen)
+    {
+      xbuf[delta] = '%';        /* undo 0-termination */
+      memmove (xbuf,
+               &xbuf[delta],
+               clen);
+    }
     xoff = clen;
   }
 }
diff --git a/src/microhttpd/test_postprocessor.c 
b/src/microhttpd/test_postprocessor.c
index 17d09c91..b3e12323 100644
--- a/src/microhttpd/test_postprocessor.c
+++ b/src/microhttpd/test_postprocessor.c
@@ -105,6 +105,17 @@ mismatch (const char *a, const char *b)
 }
 
 
+static int
+mismatch2 (const char *data, const char *expected, size_t offset, size_t size)
+{
+  if (data == expected)
+    return 0;
+  if ((data == NULL) || (expected == NULL))
+    return 1;
+  return 0 != memcmp (data, expected + offset, size);
+}
+
+
 static enum MHD_Result
 value_checker (void *cls,
                enum MHD_ValueKind kind,
@@ -144,9 +155,7 @@ value_checker (void *cls,
       (mismatch (filename, expct->fname)) ||
       (mismatch (content_type, expct->cnt_type)) ||
       (mismatch (transfer_encoding, expct->tr_enc)) ||
-      (0 != memcmp (data,
-                    &expct->data[off],
-                    size)))
+      (mismatch2 (data, expct->data, off, size)))
   {
     *idxp = (unsigned int) -1;
     fprintf (stderr,
@@ -171,7 +180,7 @@ value_checker (void *cls,
              (mismatch (filename, expct->fname)),
              (mismatch (content_type, expct->cnt_type)),
              (mismatch (transfer_encoding, expct->tr_enc)),
-             (0 != memcmp (data, &expct->data[off], size)));
+             (mismatch2 (data, expct->data, off, size)));
     return MHD_NO;
   }
   if ( ( (NULL == expct->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]