gnunet-svn
[Top][All Lists]
Advanced

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

[libmicrohttpd] branch master updated (f50153e5 -> a7aa1266)


From: gnunet
Subject: [libmicrohttpd] branch master updated (f50153e5 -> a7aa1266)
Date: Thu, 05 May 2022 13:56:04 +0200

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

karlson2k pushed a change to branch master
in repository libmicrohttpd.

    from f50153e5 configure: added 'debugger' build type
     new cc88b5a0 connection.c: fixed doxy
     new a7aa1266 test_parse_cookies: added more checks

The 2 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/connection.c       |   2 +-
 src/testcurl/test_parse_cookies.c | 143 ++++++++++++++++++++++++++++----------
 2 files changed, 108 insertions(+), 37 deletions(-)

diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index 9f0016b5..0a3dc282 100644
--- a/src/microhttpd/connection.c
+++ b/src/microhttpd/connection.c
@@ -235,7 +235,7 @@ str_conn_error_ (ssize_t mhd_err_code)
 
 /**
  * Allocate memory from connection's memory pool.
- * If memory pool doesn't have enough free memory but read of write buffer
+ * If memory pool doesn't have enough free memory but read or write buffer
  * have some unused memory, the size of the buffer will be reduced as needed.
  * @param connection the connection to use
  * @param size the size of allocated memory area
diff --git a/src/testcurl/test_parse_cookies.c 
b/src/testcurl/test_parse_cookies.c
index 0fc5ffc1..d124b3a9 100644
--- a/src/testcurl/test_parse_cookies.c
+++ b/src/testcurl/test_parse_cookies.c
@@ -31,6 +31,7 @@
 #include <curl/curl.h>
 #include <microhttpd.h>
 #include <stdlib.h>
+#include <stdio.h>
 #include <string.h>
 #include <time.h>
 #include "mhd_has_in_name.h"
@@ -71,13 +72,13 @@ ahc_echo (void *cls,
           void **req_cls)
 {
   static int ptr;
-  const char *me = cls;
+  const int *puse_invalid = cls;
   struct MHD_Response *response;
   enum MHD_Result ret;
   const char *hdr;
   (void) version; (void) upload_data; (void) upload_data_size;       /* 
Unused. Silent compiler warning. */
 
-  if (0 != strcmp (me, method))
+  if (0 != strcmp (MHD_HTTP_METHOD_GET, method))
     return MHD_NO;              /* unexpected method */
   if (&ptr != *req_cls)
   {
@@ -86,21 +87,50 @@ ahc_echo (void *cls,
   }
   *req_cls = NULL;
 
-  hdr = MHD_lookup_connection_value (connection, MHD_COOKIE_KIND, "name1");
-  if ((hdr == NULL) || (0 != strcmp (hdr, "var1")))
-    abort ();
-  hdr = MHD_lookup_connection_value (connection, MHD_COOKIE_KIND, "name2");
-  if ((hdr == NULL) || (0 != strcmp (hdr, "var2")))
-    abort ();
-  hdr = MHD_lookup_connection_value (connection, MHD_COOKIE_KIND, "name3");
-  if ((hdr == NULL) || (0 != strcmp (hdr, "")))
-    abort ();
-  hdr = MHD_lookup_connection_value (connection, MHD_COOKIE_KIND, "name4");
-  if ((hdr == NULL) || (0 != strcmp (hdr, "var4 with spaces")))
-    abort ();
-  response = MHD_create_response_from_buffer (strlen (url),
-                                              (void *) url,
-                                              MHD_RESPMEM_PERSISTENT);
+  if (! *puse_invalid)
+  {
+    hdr = MHD_lookup_connection_value (connection, MHD_COOKIE_KIND, "name1");
+    if ((hdr == NULL) || (0 != strcmp (hdr, "var1")))
+    {
+      fprintf (stderr, "'name1' cookie decoded incorrectly.\n");
+      exit (11);
+    }
+    hdr = MHD_lookup_connection_value (connection, MHD_COOKIE_KIND, "name2");
+    if ((hdr == NULL) || (0 != strcmp (hdr, "var2")))
+    {
+      fprintf (stderr, "'name2' cookie decoded incorrectly.\n");
+      exit (11);
+    }
+    hdr = MHD_lookup_connection_value (connection, MHD_COOKIE_KIND, "name3");
+    if ((hdr == NULL) || (0 != strcmp (hdr, "")))
+    {
+      fprintf (stderr, "'name3' cookie decoded incorrectly.\n");
+      exit (11);
+    }
+    hdr = MHD_lookup_connection_value (connection, MHD_COOKIE_KIND, "name4");
+    if ((hdr == NULL) || (0 != strcmp (hdr, "var4 with spaces")))
+    {
+      fprintf (stderr, "'name4' cookie decoded incorrectly.\n");
+      exit (11);
+    }
+    if (4 != MHD_get_connection_values_n (connection, MHD_COOKIE_KIND,
+                                          NULL, NULL))
+    {
+      fprintf (stderr, "The total number of cookie is not four.\n");
+      exit (12);
+    }
+  }
+  else
+  {
+    if (0 != MHD_get_connection_values_n (connection, MHD_COOKIE_KIND,
+                                          NULL, NULL))
+    {
+      fprintf (stderr, "The total number of cookie is not zero.\n");
+      exit (12);
+    }
+  }
+  response = MHD_create_response_from_buffer_copy (strlen (url),
+                                                   url);
   ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
   MHD_destroy_response (response);
   if (ret == MHD_NO)
@@ -109,8 +139,11 @@ ahc_echo (void *cls,
 }
 
 
-static int
-testExternalGet ()
+/* Re-use the same port for all checks */
+static unsigned int port;
+
+static unsigned int
+testExternalGet (int use_invalid)
 {
   struct MHD_Daemon *d;
   CURL *c;
@@ -131,23 +164,14 @@ testExternalGet ()
   struct CURLMsg *msg;
   time_t start;
   struct timeval tv;
-  int port;
-
-  if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
-    port = 0;
-  else
-  {
-    port = 1340;
-    if (oneone)
-      port += 5;
-  }
 
   multi = NULL;
   cbc.buf = buf;
   cbc.size = 2048;
   cbc.pos = 0;
   d = MHD_start_daemon (MHD_USE_ERROR_LOG,
-                        port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END);
+                        port, NULL, NULL, &ahc_echo, &use_invalid,
+                        MHD_OPTION_END);
   if (d == NULL)
     return 256;
   if (0 == port)
@@ -166,11 +190,44 @@ testExternalGet ()
   curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
   curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
   curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
-  /* note that the string below intentionally uses the
-     various ways cookies can be specified to exercise the
-     parser! Do not change! */
-  curl_easy_setopt (c, CURLOPT_COOKIE,
-                    "name1=var1; name2=var2,name3 ;name4=\"var4 with 
spaces\";");
+  if (0 == use_invalid)
+  {
+    curl_easy_setopt (c, CURLOPT_COOKIE,
+                      "name1=var1; name2=var2,name3 ;" \
+                      "name4=\"var4 with spaces\";" \
+                      " ;   ;; ;");
+  }
+  else if (1 == use_invalid)
+  {
+    curl_easy_setopt (c, CURLOPT_COOKIE,
+                      "var1=value1=");
+  }
+  else if (2 == use_invalid)
+  {
+    curl_easy_setopt (c, CURLOPT_COOKIE,
+                      "var1=value1;=;");
+  }
+  else if (3 == use_invalid)
+  {
+    curl_easy_setopt (c, CURLOPT_COOKIE,
+                      "=");
+  }
+  else if (4 == use_invalid)
+  {
+    curl_easy_setopt (c, CURLOPT_COOKIE,
+                      ";=");
+  }
+  else if (5 == use_invalid)
+  {
+    curl_easy_setopt (c, CURLOPT_COOKIE,
+                      "=;");
+  }
+  else if (6 == use_invalid)
+  {
+    curl_easy_setopt (c, CURLOPT_COOKIE,
+                      "a=b,d=c");
+  }
+
   if (oneone)
     curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
   else
@@ -309,7 +366,21 @@ main (int argc, char *const *argv)
   oneone = has_in_name (argv[0], "11");
   if (0 != curl_global_init (CURL_GLOBAL_WIN32))
     return 2;
-  errorCount += testExternalGet ();
+  if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
+    port = 0;
+  else
+  {
+    port = 1340;
+    if (oneone)
+      port += 5;
+  }
+  errorCount += testExternalGet (0);
+  errorCount += testExternalGet (1);
+  errorCount += testExternalGet (2);
+  errorCount += testExternalGet (3);
+  errorCount += testExternalGet (4);
+  errorCount += testExternalGet (5);
+  errorCount += testExternalGet (6);
   if (errorCount != 0)
     fprintf (stderr, "Error (code: %u)\n", errorCount);
   curl_global_cleanup ();

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