gnunet-svn
[Top][All Lists]
Advanced

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

[libmicrohttpd] branch master updated (1cf2ccde -> 495da114)


From: gnunet
Subject: [libmicrohttpd] branch master updated (1cf2ccde -> 495da114)
Date: Wed, 15 Sep 2021 20:18:43 +0200

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

karlson2k pushed a change to branch master
in repository libmicrohttpd.

    from 1cf2ccde test_postprocessor: added test with double value
     new ddcc20a0 postprocessor: minor code improvement
     new 0d467e4c test_postprocessor: report more details
     new 495da114 test_postprocessor: added testing of hex-encoded values

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      | 47 ++++++++++++++++++++-----------------
 src/microhttpd/test_postprocessor.c | 27 +++++++++++++++++----
 2 files changed, 49 insertions(+), 25 deletions(-)

diff --git a/src/microhttpd/postprocessor.c b/src/microhttpd/postprocessor.c
index 2720e916..9b87554a 100644
--- a/src/microhttpd/postprocessor.c
+++ b/src/microhttpd/postprocessor.c
@@ -646,25 +646,27 @@ post_process_urlencoded (struct MHD_PostProcessor *pp,
       break;
     case PP_Callback:
       mhd_assert ((NULL != end_key) || (NULL == start_key));
-      if ( (pp->buffer_pos + (end_key - start_key) >=
-            pp->buffer_size) ||
-           (pp->buffer_pos + (end_key - start_key) <
-            pp->buffer_pos) )
+      if (1)
       {
-        /* key too long, cannot parse! */
-        pp->state = PP_Error;
-        continue;
-      }
-      /* compute key, if we have not already */
-      if (NULL != start_key)
-      {
-        memcpy (&kbuf[pp->buffer_pos],
-                start_key,
-                end_key - start_key);
-        pp->buffer_pos += end_key - start_key;
-        start_key = NULL;
-        end_key = NULL;
-        pp->must_unescape_key = true;
+        const size_t key_len = end_key - start_key;
+        if (0 != key_len)
+        {
+          if ( (pp->buffer_pos + key_len >= pp->buffer_size) ||
+               (pp->buffer_pos + key_len < pp->buffer_pos) )
+          {
+            /* key too long, cannot parse! */
+            pp->state = PP_Error;
+            continue;
+          }
+          /* compute key, if we have not already */
+          memcpy (&kbuf[pp->buffer_pos],
+                  start_key,
+                  key_len);
+          pp->buffer_pos += key_len;
+          start_key = NULL;
+          end_key = NULL;
+          pp->must_unescape_key = true;
+        }
       }
       if (pp->must_unescape_key)
       {
@@ -706,18 +708,21 @@ post_process_urlencoded (struct MHD_PostProcessor *pp,
   /* save remaining data for next iteration */
   if (NULL != start_key)
   {
+    size_t key_len;
     mhd_assert ((PP_Init == pp->state) || (NULL != end_key));
     if (NULL == end_key)
       end_key = &post_data[poff];
-    if (pp->buffer_pos + (end_key - start_key) >= pp->buffer_size)
+    key_len = end_key - start_key;
+    mhd_assert (0 != key_len); /* it must be always non-zero here */
+    if (pp->buffer_pos + key_len >= pp->buffer_size)
     {
       pp->state = PP_Error;
       return MHD_NO;
     }
     memcpy (&kbuf[pp->buffer_pos],
             start_key,
-            end_key - start_key);
-    pp->buffer_pos += end_key - start_key;
+            key_len);
+    pp->buffer_pos += key_len;
     pp->must_unescape_key = true;
     start_key = NULL;
     end_key = NULL;
diff --git a/src/microhttpd/test_postprocessor.c 
b/src/microhttpd/test_postprocessor.c
index b3231c0e..8d740b62 100644
--- a/src/microhttpd/test_postprocessor.c
+++ b/src/microhttpd/test_postprocessor.c
@@ -78,10 +78,17 @@ struct expResult exp_results[] = {
   {"abc", NULL, NULL, NULL, "def"},
   {"x", NULL, NULL, NULL, "5"},
 #define URL_END (URL_START + 2)
+#define URL_ENC_DATA "space=%20&key%201=&crlf=%0D%0a&mix%09ed=%2001%0d%0A"
+#define URL_ENC_START URL_END
+  {"space", NULL, NULL, NULL, " "},
+  {"key 1", NULL, NULL, NULL, ""},
+  {"crlf", NULL, NULL, NULL, "\r\n"},
+  {"mix\ted", NULL, NULL, NULL, " 01\r\n"},
+#define URL_ENC_END (URL_ENC_START + 4)
   {NULL, NULL, NULL, NULL, NULL},
 #define FORM_DATA \
   "--AaB03x\r\ncontent-disposition: form-data; name=\"field1\"\r\n\r\nJoe 
Blow\r\n--AaB03x\r\ncontent-disposition: form-data; name=\"pics\"; 
filename=\"file1.txt\"\r\nContent-Type: 
text/plain\r\nContent-Transfer-Encoding: 
binary\r\n\r\nfiledata\r\n--AaB03x--\r\n"
-#define FORM_START (URL_END + 1)
+#define FORM_START (URL_ENC_END + 1)
   {"field1", NULL, NULL, NULL, "Joe Blow"},
   {"pics", "file1.txt", "text/plain", "binary", "filedata"},
 #define FORM_END (FORM_START + 2)
@@ -209,6 +216,7 @@ test_urlencoding_case (unsigned int want_start,
                        const char *url_data)
 {
   size_t step;
+  int errors = 0;
   const size_t size = strlen (url_data);
 
   for (step = 1; size >= step; ++step)
@@ -256,15 +264,17 @@ test_urlencoding_case (unsigned int want_start,
     if (want_off != want_end)
     {
       fprintf (stderr,
-               "Test failed in line %u.\tStep:%u\n Got: %u\tExpected: %u\n",
+               "Test failed in line %u.\tStep: %u.\tData: \"%s\"\n" \
+               " Got: %u\tExpected: %u\n",
                (unsigned int) __LINE__,
                (unsigned int) step,
+               url_data,
                want_off,
                want_end);
-      return 1;
+      errors++;
     }
   }
-  return 0;
+  return errors;
 }
 
 
@@ -276,6 +286,9 @@ test_urlencoding (void)
   errorCount += test_urlencoding_case (URL_START,
                                        URL_END,
                                        URL_DATA);
+  errorCount += test_urlencoding_case (URL_ENC_START,
+                                       URL_ENC_END,
+                                       URL_ENC_DATA);
   errorCount += test_urlencoding_case (URL_NOVALUE1_START,
                                        URL_NOVALUE1_END,
                                        URL_NOVALUE1_DATA);
@@ -295,6 +308,9 @@ test_urlencoding (void)
   errorCount += test_urlencoding_case (URL_START,
                                        URL_END,
                                        URL_DATA "\n");
+  errorCount += test_urlencoding_case (URL_ENC_START,
+                                       URL_ENC_END,
+                                       URL_ENC_DATA "\n");
   errorCount += test_urlencoding_case (URL_NOVALUE1_START,
                                        URL_NOVALUE1_END,
                                        URL_NOVALUE1_DATA "\n");
@@ -314,6 +330,9 @@ test_urlencoding (void)
   errorCount += test_urlencoding_case (URL_START,
                                        URL_END,
                                        "&&" URL_DATA);
+  errorCount += test_urlencoding_case (URL_ENC_START,
+                                       URL_ENC_END,
+                                       "&&" URL_ENC_DATA);
   errorCount += test_urlencoding_case (URL_NOVALUE1_START,
                                        URL_NOVALUE1_END,
                                        "&&" URL_NOVALUE1_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]