gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [taler-twister] 31/34: implement upload data malformation.


From: gnunet
Subject: [GNUnet-SVN] [taler-twister] 31/34: implement upload data malformation.
Date: Sat, 17 Mar 2018 01:58:22 +0100

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

marcello pushed a commit to branch master
in repository twister.

commit 0f30e5ab837a144164b6af7d3006b5cc5ea6b9ed
Author: Marcello Stanisci <address@hidden>
AuthorDate: Thu Mar 15 19:10:42 2018 +0100

    implement upload data malformation.
---
 src/include/taler_twister_service.h | 14 +++++++++
 src/twister/taler-twister-service.c | 60 +++++++++++++++++++++++++++++++++----
 src/twister/taler-twister.c         | 18 +++++++++++
 src/twister/twister.h               |  2 ++
 src/twister/twister_api.c           | 37 +++++++++++++++++++++++
 5 files changed, 126 insertions(+), 5 deletions(-)

diff --git a/src/include/taler_twister_service.h 
b/src/include/taler_twister_service.h
index 701633d..486baf2 100644
--- a/src/include/taler_twister_service.h
+++ b/src/include/taler_twister_service.h
@@ -126,6 +126,20 @@ TALER_TWISTER_malform
    void *cb_cls);
 
 /**
+ * Randomly truncate the request.
+ *
+ * @param h twister instance to control
+ * @param cb function to call once twister is ready
+ * @param cb_cls closure for @a cb
+ * @return operation handle (to possibly abort)
+ */
+struct TALER_TWISTER_Operation *
+TALER_TWISTER_malform_upload
+  (struct TALER_TWISTER_Handle *h,
+   GNUNET_SCHEDULER_TaskCallback cb,
+   void *cb_cls);
+
+/**
  * Delete the object pointed to by @a path.
  *
  * @param h twister instance to control
diff --git a/src/twister/taler-twister-service.c 
b/src/twister/taler-twister-service.c
index 75e89f6..a0477b8 100644
--- a/src/twister/taler-twister-service.c
+++ b/src/twister/taler-twister-service.c
@@ -253,6 +253,12 @@ static char delete_path[TWISTER_PATH_LENGTH] = {'\0'};
 static char modify_path[TWISTER_PATH_LENGTH] = {'\0'};
 
 /**
+ * If true, will randomly truncate the request body
+ * to upload to the proxied service.
+ */
+static unsigned int malform_upload = GNUNET_NO;
+
+/**
  * If true, will randomly truncate the response before
  * returning to the client.
  */
@@ -533,8 +539,8 @@ curl_download_cb (void *ptr,
 
 
 /**
- * cURL callback for uploaded (PUT/POST) data.  Copies from our `io_buf`
- * to make it available to curl.
+ * cURL callback for uploaded (PUT/POST) data.
+ * Copies from our `io_buf` to make it available to curl.
  *
  * @param buf where to write the data
  * @param size number of bytes per member
@@ -583,7 +589,7 @@ curl_upload_cb (void *buf,
 }
 
 
-/* ************************** main loop of cURL interaction ****************** 
*/
+/* ************** main loop of cURL interaction ************* */
 
 
 /**
@@ -1080,24 +1086,44 @@ create_response (void *cls,
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "Processing %u bytes UPLOAD\n",
                (unsigned int) *upload_data_size);
+
+    /* Grow the buffer if remaining space isn't enough.  */
     if (hr->io_size - hr->io_len < *upload_data_size)
     {
+      /* How can this assertion be false?  */
       GNUNET_assert (hr->io_size * 2 + 1024 > hr->io_size);
+      /* This asserts that upload_data_size > 0, ?  */
       GNUNET_assert (*upload_data_size + hr->io_len > hr->io_len);
+
       GNUNET_array_grow (hr->io_buf,
                         hr->io_size,
                         GNUNET_MAX
                            (hr->io_size * 2 + 1024,
                            *upload_data_size + hr->io_len));
     }
+
+    /* Finally copy upload data.  */
     GNUNET_memcpy (&hr->io_buf[hr->io_len],
                    upload_data,
                    *upload_data_size);
+
+    /* Note, each request starts with fresh and
+     * equal-to-zero io_len (?).  */
     hr->io_len += *upload_data_size;
     *upload_data_size = 0;
     return MHD_YES;
   }
 
+  /* Malform request body. */
+  if (GNUNET_YES == malform_upload)
+  {
+    TALER_LOG_DEBUG
+      ("Will (badly) truncate the request.\n");
+    hr->io_len = GNUNET_CRYPTO_random_u32
+      (GNUNET_CRYPTO_QUALITY_WEAK, hr->io_len - 1);
+    malform_upload = GNUNET_NO;
+  }
+
   /* Upload finished, generate curl request */
   if (NULL == hr->curl)
   {
@@ -1105,9 +1131,12 @@ create_response (void *cls,
                 "Generating curl request\n");
     hr->curl = curl_easy_init ();
     if (NULL == hr->curl)
+    {
+      TALER_LOG_ERROR ("Could not init the curl handle\n");
       return MHD_queue_response (con,
                                  MHD_HTTP_INTERNAL_SERVER_ERROR,
                                  curl_failure_response);
+    }
     if (0 != hr->io_len)
       curl_easy_setopt (hr->curl,
                        CURLOPT_POSTFIELDSIZE,
@@ -1315,9 +1344,9 @@ create_response (void *cls,
     size_t fake_len;
 
     TALER_LOG_DEBUG
-      ("Will (badly) truncate the original output.\n");
+      ("Will (badly) truncate the response.\n");
     fake_len = GNUNET_CRYPTO_random_u32
-      (GNUNET_CRYPTO_QUALITY_WEAK, hr->io_len);
+      (GNUNET_CRYPTO_QUALITY_WEAK, hr->io_len - 1);
     body_len = fake_len; 
     malform = GNUNET_NO;
   }
@@ -1775,6 +1804,22 @@ handle_malform (void *cls,
   send_acknowledgement (c);
 }
 
+/**
+ * Control handler for malforming requests.
+ *
+ * @param cls message queue for sending replies
+ * @param src received message
+ */
+static void
+handle_malform_upload (void *cls,
+                       const struct TWISTER_Malform *src)
+{
+  struct GNUNET_SERVICE_Client *c = cls;
+
+  TALER_LOG_DEBUG ("Flagging request malformation\n");
+  malform_upload = GNUNET_YES;
+  send_acknowledgement (c);
+}
 
 /**
  * Control handler for deleting JSON objects
@@ -1849,6 +1894,11 @@ GNUNET_SERVICE_MAIN
                          struct TWISTER_ModifyPath,
                          NULL),
 
+ GNUNET_MQ_hd_fixed_size (malform_upload,
+                         TWISTER_MESSAGE_TYPE_MALFORM_UPLOAD,
+                         struct TWISTER_Malform,
+                         NULL),
+
  GNUNET_MQ_hd_fixed_size (malform,
                          TWISTER_MESSAGE_TYPE_MALFORM,
                          struct TWISTER_Malform,
diff --git a/src/twister/taler-twister.c b/src/twister/taler-twister.c
index 2807bab..ce39104 100644
--- a/src/twister/taler-twister.c
+++ b/src/twister/taler-twister.c
@@ -58,6 +58,11 @@ static char *delete_path;
 static int malform_response;
 
 /**
+ * If true, will randomly truncate the proxied request.
+ */
+static int malform_upload;
+
+/**
  * Path to the object to modify.
  */
 static char *modify_path;
@@ -139,6 +144,13 @@ run (void *cls,
     return;
   }
 
+  if ( (0 != malform_upload) &&
+       (NULL != TALER_TWISTER_malform_upload
+         (tth,
+          &handle_acknowledgement,
+          NULL)))
+    num_ops++;
+
   if ( (0 != malform_response) &&
        (NULL != TALER_TWISTER_malform
          (tth,
@@ -241,6 +253,12 @@ main (int argc,
        &check_alive),
 
     GNUNET_GETOPT_option_flag
+      ('U',
+       "malformupload",
+       gettext_noop ("Randomly truncate proxied request"),
+       &malform_upload),
+
+    GNUNET_GETOPT_option_flag
       ('M',
        "malform",
        gettext_noop ("Randomly truncate proxied response"),
diff --git a/src/twister/twister.h b/src/twister/twister.h
index 5954b3c..c1ebeef 100644
--- a/src/twister/twister.h
+++ b/src/twister/twister.h
@@ -49,6 +49,8 @@
 
 #define TWISTER_MESSAGE_TYPE_MALFORM 5
 
+#define TWISTER_MESSAGE_TYPE_MALFORM_UPLOAD 6
+
 GNUNET_NETWORK_STRUCT_BEGIN
 struct TWISTER_Malform
 {
diff --git a/src/twister/twister_api.c b/src/twister/twister_api.c
index b81b7b8..477b774 100644
--- a/src/twister/twister_api.c
+++ b/src/twister/twister_api.c
@@ -202,6 +202,43 @@ TALER_TWISTER_cancel (struct TALER_TWISTER_Operation *op)
   op->cb = NULL;
 }
 
+
+/**
+ * Randomly truncate the request.
+ *
+ * @param h twister instance to control
+ * @param cb function to call once twister is ready
+ * @param cb_cls closure for @a cb
+ * @return operation handle (to possibly abort)
+ */
+struct TALER_TWISTER_Operation *
+TALER_TWISTER_malform_upload
+  (struct TALER_TWISTER_Handle *h,
+   GNUNET_SCHEDULER_TaskCallback cb,
+   void *cb_cls)
+{
+  struct TALER_TWISTER_Operation *op;
+  struct GNUNET_MQ_Envelope *env;
+  struct TWISTER_Malform *src;
+
+  op = GNUNET_new (struct TALER_TWISTER_Operation);
+  op->h = h;
+  op->cb = cb;
+  op->cb_cls = cb_cls;
+  GNUNET_CONTAINER_DLL_insert_tail (h->op_head,
+                                    h->op_tail,
+                                    op);
+  /* Prepare *env*elope. */
+  env = GNUNET_MQ_msg
+    (src, TWISTER_MESSAGE_TYPE_MALFORM_UPLOAD);
+  /* Send message. */
+  GNUNET_MQ_send (h->mq, env);
+  LOG (GNUNET_ERROR_TYPE_DEBUG,
+       "Batching a (upload) body malformation\n");
+  return op;
+}
+
+
 /**
  * Randomly truncate the response.
  *

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

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