gnunet-svn
[Top][All Lists]
Advanced

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

[libmicrohttpd] branch master updated (cb1fabe8 -> 3e50200e)


From: gnunet
Subject: [libmicrohttpd] branch master updated (cb1fabe8 -> 3e50200e)
Date: Sat, 11 Jul 2020 19:45:59 +0200

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

grothoff pushed a change to branch master
in repository libmicrohttpd.

    from cb1fabe8 version bump
     new 774c461f extending test (MD)
     new 1899a24a Merge branch 'master' of git+ssh://gnunet.org/libmicrohttpd
     new 3e50200e fixing pp regression

The 3 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         | 88 ++++++++++++++++++++++------------
 src/microhttpd/test_postprocessor_md.c | 52 ++++++++++++++++++++
 2 files changed, 110 insertions(+), 30 deletions(-)

diff --git a/src/microhttpd/postprocessor.c b/src/microhttpd/postprocessor.c
index ecdef5a8..43ca1c4b 100644
--- a/src/microhttpd/postprocessor.c
+++ b/src/microhttpd/postprocessor.c
@@ -379,6 +379,7 @@ process_value (struct MHD_PostProcessor *pp,
   size_t xoff;
 
   mhd_assert (pp->xbuf_pos < sizeof (xbuf));
+  /* move remaining input from previous round into processing buffer */
   memcpy (xbuf,
           pp->xbuf,
           pp->xbuf_pos);
@@ -401,60 +402,87 @@ process_value (struct MHD_PostProcessor *pp,
   {
     size_t delta = value_end - value_start;
     bool cut = false;
+    size_t clen = 0;
 
     if (delta > XBUF_SIZE - xoff)
       delta = XBUF_SIZE - xoff;
-    /* move input into processing buffer */
+    /* move (additional) input into processing buffer */
     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) */
-    if ( (xoff + delta > 0) &&
-         ('%' == xbuf[xoff + delta - 1]) )
+    if ( (xoff > 0) &&
+         ('%' == xbuf[xoff - 1]) )
     {
-      cut = (delta != XBUF_SIZE - xoff);
-      delta--;
-      pp->xbuf[0] = '%';
-      pp->xbuf_pos = 1;
+      cut = (xoff != XBUF_SIZE);
+      xoff--;
+      if (cut)
+      {
+        /* move escape sequence into buffer for next function invocation */
+        pp->xbuf[0] = '%';
+        pp->xbuf_pos = 1;
+      }
+      else
+      {
+        /* just skip escape sequence for next loop iteration */
+        delta = xoff;
+        clen = 1;
+      }
     }
-    else if ( (xoff + delta > 1) &&
-              ('%' == xbuf[xoff + delta - 2]) )
+    else if ( (xoff > 1) &&
+              ('%' == xbuf[xoff - 2]) )
     {
-      memcpy (pp->xbuf,
-              &xbuf[xoff + delta - 2],
-              2);
-      pp->xbuf_pos = 2;
-      cut = (delta != XBUF_SIZE - xoff);
-      delta -= 2;
+      cut = (xoff != XBUF_SIZE);
+      xoff -= 2;
+      if (cut)
+      {
+        /* move escape sequence into buffer for next function invocation */
+        memcpy (pp->xbuf,
+                &xbuf[xoff],
+                2);
+        pp->xbuf_pos = 2;
+      }
+      else
+      {
+        /* just skip escape sequence for next loop iteration */
+        delta = xoff;
+        clen = 2;
+      }
     }
-    xoff += delta;
-    value_start += delta;
     mhd_assert (xoff < sizeof (xbuf));
     /* unescape */
     xbuf[xoff] = '\0';        /* 0-terminate in preparation */
     MHD_unescape_plus (xbuf);
     xoff = MHD_http_unescape (xbuf);
     /* finally: call application! */
-    pp->must_ikvi = false;
-    if (MHD_NO == pp->ikvi (pp->cls,
-                            MHD_POSTDATA_KIND,
-                            (const char *) &pp[1],        /* key */
-                            NULL,
-                            NULL,
-                            NULL,
-                            xbuf,
-                            pp->value_offset,
-                            xoff))
+    if ( (pp->must_ikvi || (0 != xoff)) )
     {
-      pp->state = PP_Error;
-      return;
+      pp->must_ikvi = false;
+      if (MHD_NO == pp->ikvi (pp->cls,
+                              MHD_POSTDATA_KIND,
+                              (const char *) &pp[1],      /* key */
+                              NULL,
+                              NULL,
+                              NULL,
+                              xbuf,
+                              pp->value_offset,
+                              xoff))
+      {
+        pp->state = PP_Error;
+        return;
+      }
     }
     pp->value_offset += xoff;
-    xoff = 0;
     if (cut)
       break;
+    memmove (xbuf,
+             &xbuf[delta],
+             clen);
+    xoff = clen;
   }
 }
 
diff --git a/src/microhttpd/test_postprocessor_md.c 
b/src/microhttpd/test_postprocessor_md.c
index 07400f09..930f7fb3 100644
--- a/src/microhttpd/test_postprocessor_md.c
+++ b/src/microhttpd/test_postprocessor_md.c
@@ -135,6 +135,32 @@ post_data_iterator2 (void *cls,
 }
 
 
+static enum MHD_Result
+post_data_iterator3 (void *cls,
+                     enum MHD_ValueKind kind,
+                     const char *key,
+                     const char *filename,
+                     const char *content_type,
+                     const char *transfer_encoding,
+                     const char *data,
+                     uint64_t off,
+                     size_t size)
+{
+  fprintf (stderr,
+           "%s\t%s\n",
+           key,
+           data);
+  if (0 == strcmp (key, "y"))
+  {
+    if ( (1 != size) ||
+         (0 != memcmp (data, "y", 1)) )
+      exit (1);
+    found |= 1;
+  }
+  return MHD_YES;
+}
+
+
 int
 main (int argc, char *argv[])
 {
@@ -180,5 +206,31 @@ main (int argc, char *argv[])
   if (found != 1)
     exit (4);
 
+  found = 0;
+  postprocessor = malloc (sizeof (struct MHD_PostProcessor)
+                          + 0x1000 + 1);
+  if (NULL == postprocessor)
+    return 77;
+  memset (postprocessor,
+          0,
+          sizeof (struct MHD_PostProcessor) + 0x1000 + 1);
+  postprocessor->ikvi = post_data_iterator3;
+  postprocessor->encoding = MHD_HTTP_POST_ENCODING_FORM_URLENCODED;
+  postprocessor->buffer_size = 0x1000;
+  postprocessor->state = PP_Init;
+  postprocessor->skip_rn = RN_Inactive;
+  {
+    const char *chunk =
+      
"x=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx%2Cxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx%2C%2C%2C%2C%2C%2Cxxxxxxxxxxxxxxxxx%2Cxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx%2Cxxxxxxxxxxxxxxxxxxxxxxxxx%2C%2C%2C%2C%2Cxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx%2C%2C%2C%2C%2Cxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx%2C%2C%2C%2Cxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 [...]
+      "&y=y&z=z";
+
+    MHD_post_process (postprocessor, chunk, strlen (chunk) );
+  }
+  MHD_post_process (postprocessor, "", 0);
+  MHD_destroy_post_processor (postprocessor);
+
+  if (found != 1)
+    exit (5);
+
   return EXIT_SUCCESS;
 }

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