gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r30466 - in libmicrohttpd: . src/microhttpd


From: gnunet
Subject: [GNUnet-SVN] r30466 - in libmicrohttpd: . src/microhttpd
Date: Wed, 30 Oct 2013 09:35:28 +0100

Author: grothoff
Date: 2013-10-30 09:35:28 +0100 (Wed, 30 Oct 2013)
New Revision: 30466

Modified:
   libmicrohttpd/ChangeLog
   libmicrohttpd/src/microhttpd/postprocessor.c
   libmicrohttpd/src/microhttpd/test_postprocessor.c
Log:
-fix post processor, expanded test suite to cover garbage before payload

Modified: libmicrohttpd/ChangeLog
===================================================================
--- libmicrohttpd/ChangeLog     2013-10-30 00:53:38 UTC (rev 30465)
+++ libmicrohttpd/ChangeLog     2013-10-30 08:35:28 UTC (rev 30466)
@@ -1,3 +1,7 @@
+Wed Oct 30 09:34:20 CET 2013
+       Fixing issue in PostProcessor when getting partial boundary
+       at the beginning, expanding test suite. -CG
+
 Sun Oct 27 15:19:44 CET 2013
        Implementing faster processing of upload data in multipart
        encoding (thanks to performance analysis by Adam Homolya). -CG

Modified: libmicrohttpd/src/microhttpd/postprocessor.c
===================================================================
--- libmicrohttpd/src/microhttpd/postprocessor.c        2013-10-30 00:53:38 UTC 
(rev 30465)
+++ libmicrohttpd/src/microhttpd/postprocessor.c        2013-10-30 08:35:28 UTC 
(rev 30466)
@@ -533,18 +533,34 @@
                enum PP_State next_state, enum PP_State next_dash_state)
 {
   char *buf = (char *) &pp[1];
+  const char *dash;
 
   if (pp->buffer_pos < 2 + blen)
     {
       if (pp->buffer_pos == pp->buffer_size)
         pp->state = PP_Error;   /* out of memory */
-      ++(*ioffptr);
+      // ++(*ioffptr);
       return MHD_NO;            /* not enough data */
     }
   if ((0 != memcmp ("--", buf, 2)) || (0 != memcmp (&buf[2], boundary, blen)))
     {
       if (pp->state != PP_Init)
-        pp->state = PP_Error;
+        {
+          /* garbage not allowed */
+          pp->state = PP_Error;
+        }
+      else
+        {
+          /* skip over garbage (RFC 2046, 5.1.1) */
+          dash = memchr (buf, '-', pp->buffer_pos);
+          if (NULL == dash)
+            (*ioffptr) += pp->buffer_pos; /* skip entire buffer */
+          else
+            if (dash == buf)
+              (*ioffptr)++; /* at least skip one byte */
+            else
+              (*ioffptr) += dash - buf; /* skip to first possible boundary */
+        }
       return MHD_NO;            /* expected boundary */
     }
   /* remove boundary from buffer */
@@ -699,7 +715,7 @@
     {
       while (newline + 4 < pp->buffer_pos)
         {
-          r = memchr (&buf[newline], '\r', pp->buffer_pos - newline);
+          r = memchr (&buf[newline], '\r', pp->buffer_pos - newline - 4);
           if (NULL == r)
           {
             newline = pp->buffer_pos - 4;

Modified: libmicrohttpd/src/microhttpd/test_postprocessor.c
===================================================================
--- libmicrohttpd/src/microhttpd/test_postprocessor.c   2013-10-30 00:53:38 UTC 
(rev 30465)
+++ libmicrohttpd/src/microhttpd/test_postprocessor.c   2013-10-30 08:35:28 UTC 
(rev 30466)
@@ -1,10 +1,10 @@
 /*
      This file is part of libmicrohttpd
-     (C) 2007 Christian Grothoff
+     (C) 2007,2013 Christian Grothoff
 
      libmicrohttpd is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
-     by the Free Software Foundation; either version 2, or (at your
+     by the Free Software Foundation; either version 3, or (at your
      option) any later version.
 
      libmicrohttpd is distributed in the hope that it will be useful, but
@@ -94,10 +94,12 @@
 #if 0
   fprintf (stderr,
            "VC: `%s' `%s' `%s' `%s' `%.*s'\n",
-           key, filename, content_type, transfer_encoding, size, data);
+           key, filename, content_type, transfer_encoding,
+           (int) size,
+           data);
 #endif
   if ( (0 != off) && (0 == size) )
-    return MHD_YES; 
+    return MHD_YES;
   if ((idx < 0) ||
       (want[idx] == NULL) ||
       (0 != strcmp (key, want[idx])) ||
@@ -151,14 +153,53 @@
 
 
 static int
+test_multipart_garbage ()
+{
+  struct MHD_Connection connection;
+  struct MHD_HTTP_Header header;
+  struct MHD_PostProcessor *pp;
+  unsigned int want_off;
+  size_t size = strlen (FORM_DATA);
+  size_t splitpoint;
+  char xdata[size + 3];
+
+  /* fill in evil garbage at the beginning */
+  xdata[0] = '-';
+  xdata[1] = 'x';
+  xdata[2] = '\r';
+  memcpy (&xdata[3], FORM_DATA, size);
+  size += 3;
+
+  size = strlen (FORM_DATA);
+  for (splitpoint = 1; splitpoint < size; splitpoint++)
+  {
+    want_off = FORM_START;
+    memset (&connection, 0, sizeof (struct MHD_Connection));
+    memset (&header, 0, sizeof (struct MHD_HTTP_Header));
+    connection.headers_received = &header;
+    header.header = MHD_HTTP_HEADER_CONTENT_TYPE;
+    header.value =
+      MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA ", boundary=AaB03x";
+    header.kind = MHD_HEADER_KIND;
+    pp = MHD_create_post_processor (&connection,
+                                    1024, &value_checker, &want_off);
+    MHD_post_process (pp, xdata, splitpoint);
+    MHD_post_process (pp, &xdata[splitpoint], size - splitpoint);
+    MHD_destroy_post_processor (pp);
+    if (want_off != FORM_END)
+      return (int) splitpoint;
+  }
+  return 0;
+}
+
+
+static int
 test_multipart_splits ()
 {
   struct MHD_Connection connection;
   struct MHD_HTTP_Header header;
   struct MHD_PostProcessor *pp;
   unsigned int want_off;
-  int i;
-  int delta;
   size_t size;
   size_t splitpoint;
 
@@ -175,13 +216,8 @@
     header.kind = MHD_HEADER_KIND;
     pp = MHD_create_post_processor (&connection,
                                     1024, &value_checker, &want_off);
-    i = 0;
-    delta = splitpoint;
-    MHD_post_process (pp, &FORM_DATA[i], delta);
-    i += delta;
-    delta = 1 + size - i;
-    MHD_post_process (pp, &FORM_DATA[i], delta);
-    i += delta;
+    MHD_post_process (pp, FORM_DATA, splitpoint);
+    MHD_post_process (pp, &FORM_DATA[splitpoint], size - splitpoint);
     MHD_destroy_post_processor (pp);
     if (want_off != FORM_END)
       return (int) splitpoint;
@@ -301,8 +337,9 @@
 {
   unsigned int errorCount = 0;
 
+  errorCount += test_multipart_splits ();
+  errorCount += test_multipart_garbage ();
   errorCount += test_urlencoding ();
-  errorCount += test_multipart_splits ();
   errorCount += test_multipart ();
   errorCount += test_nested_multipart ();
   errorCount += test_empty_value ();




reply via email to

[Prev in Thread] Current Thread [Next in Thread]