gnunet-svn
[Top][All Lists]
Advanced

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

[libmicrohttpd] branch master updated: postprocessor: improved key parsi


From: gnunet
Subject: [libmicrohttpd] branch master updated: postprocessor: improved key parsing
Date: Wed, 15 Sep 2021 15:45:55 +0200

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

karlson2k pushed a commit to branch master
in repository libmicrohttpd.

The following commit(s) were added to refs/heads/master by this push:
     new d811886d postprocessor: improved key parsing
d811886d is described below

commit d811886d0393ac16dfaeb08ea9c33e6d92426750
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
AuthorDate: Wed Sep 15 16:45:18 2021 +0300

    postprocessor: improved key parsing
---
 src/microhttpd/postprocessor.c | 53 ++++++++++++++++++++++++++++--------------
 1 file changed, 36 insertions(+), 17 deletions(-)

diff --git a/src/microhttpd/postprocessor.c b/src/microhttpd/postprocessor.c
index 6f1d07e2..2720e916 100644
--- a/src/microhttpd/postprocessor.c
+++ b/src/microhttpd/postprocessor.c
@@ -1,6 +1,6 @@
 /*
      This file is part of libmicrohttpd
-     Copyright (C) 2007-2021 Daniel Pittman and Christian Grothoff
+     Copyright (C) 2007-2021 Daniel Pittman, Christian Grothoff, and Evgeny 
Grin
 
      This library is free software; you can redistribute it and/or
      modify it under the terms of the GNU Lesser General Public
@@ -21,6 +21,7 @@
  * @file postprocessor.c
  * @brief  Methods for parsing POST data
  * @author Christian Grothoff
+ * @author Karlson2k (Evgeny Grin)
  */
 
 #include "internal.h"
@@ -513,46 +514,60 @@ post_process_urlencoded (struct MHD_PostProcessor *pp,
       break;
     case PP_Init:
       /* key phase */
-      if (NULL == start_key)
-        start_key = &post_data[poff];
-      pp->must_ikvi = true;
       switch (post_data[poff])
       {
       case '=':
         /* Case: 'key=' */
-        end_key = &post_data[poff];
-        if ((start_key == end_key) && (0 == pp->buffer_pos))
+        if (NULL == start_key)
         {
-          /* Empty key with value */
-          pp->state = PP_Error;
-          continue;
+          if (0 == pp->buffer_pos)
+          {
+            /* Empty key with value */
+            pp->state = PP_Error;
+            continue;
+          }
         }
+        else
+          end_key = &post_data[poff];
         poff++;
         pp->state = PP_ProcessValue;
         break;
       case '&':
         /* Case: 'key&' */
-        end_key = &post_data[poff];
         mhd_assert (NULL == start_value);
         mhd_assert (NULL == end_value);
-        poff++;
-        if ((start_key == end_key) && (0 == pp->buffer_pos))
+        if (NULL == start_key)
         {
-          /* Empty key without value */
-          start_key = NULL;
-          continue;
+          if (0 == pp->buffer_pos)
+          {
+            /* Empty key without value */
+            poff++;
+            continue;
+          }
         }
+        else
+          end_key = &post_data[poff];
+        poff++;
         pp->state = PP_Callback;
         break;
       case '\n':
       case '\r':
         /* Case: 'key\n' or 'key\r' */
-        end_key = &post_data[poff];
+        if (NULL != start_key)
+          end_key = &post_data[poff];
         poff++;
-        pp->state = PP_Done;
+        if (pp->must_ikvi)
+          pp->state = PP_Callback;
+        else
+          pp->state = PP_Done;
         break;
       default:
         /* normal character, advance! */
+        if (NULL == start_key)
+        {
+          start_key = &post_data[poff];
+          pp->must_ikvi = true;
+        }
         poff++;
         continue;
       }
@@ -676,8 +691,12 @@ post_process_urlencoded (struct MHD_PostProcessor *pp,
                  __LINE__,
                  NULL);              /* should never happen! */
     }
+    mhd_assert ((end_key == NULL) || (start_key != NULL));
+    mhd_assert ((end_value == NULL) || (start_value != NULL));
   }
 
+  mhd_assert (PP_Callback != pp->state);
+
   if (PP_Error == pp->state)
   {
     /* State in error, returning failure */

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