commit a1537b1d94677db84807a755f134b076d2b728e6
parent 650fbad5b606361507b457c835c4b127c4405594
Author: Marcello Stanisci <stanisci.m@gmail.com>
Date: Tue, 15 May 2018 17:36:02 +0200
do not use "tmp" buffer for response
Diffstat:
1 file changed, 33 insertions(+), 36 deletions(-)
diff --git a/src/twister/taler-twister-service.c b/src/twister/taler-twister-service.c
@@ -542,7 +542,8 @@ curl_download_cb (void *ptr,
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Curl download proceeding\n");
- GNUNET_assert (REQUEST_STATE_DOWNLOAD_STARTED == hr->state);
+ GNUNET_assert
+ (REQUEST_STATE_DOWNLOAD_STARTED == hr->state);
if (hr->io_size - hr->io_len < total)
{
@@ -553,6 +554,7 @@ curl_download_cb (void *ptr,
GNUNET_MAX (total + hr->io_len,
hr->io_size * 2 + 1024));
}
+
GNUNET_memcpy (&hr->io_buf[hr->io_len],
ptr,
total);
@@ -581,6 +583,10 @@ curl_upload_cb (void *buf,
size_t len = size * nmemb;
size_t to_copy;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Uploader cb, size: %u.\n",
+ size);
+
if (REQUEST_STATE_UPLOAD_STARTED != hr->state)
{
GNUNET_break (0);
@@ -1177,9 +1183,6 @@ create_response (void *cls,
(void) cls;
(void) url;
- char *body;
- size_t body_len;
-
if (NULL == hr)
{
GNUNET_break (0);
@@ -1196,7 +1199,9 @@ create_response (void *cls,
/* continuing to process request */
if (0 != *upload_data_size)
{
- GNUNET_assert (REQUEST_STATE_UPLOAD_STARTED == hr->state);
+ GNUNET_assert
+ (REQUEST_STATE_UPLOAD_STARTED == hr->state);
+
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Processing %u bytes UPLOAD\n",
(unsigned int) *upload_data_size);
@@ -1226,49 +1231,41 @@ create_response (void *cls,
return MHD_YES;
}
- /* Malform request body. Note, this flag will be
- * cleared only after having set the right malformed
- * body lenght in the request headers. */
- if (GNUNET_YES == malform_upload)
- {
- TALER_LOG_DEBUG
- ("Will (badly) truncate the request.\n");
- malformed_size = GNUNET_CRYPTO_random_u32
- (GNUNET_CRYPTO_QUALITY_WEAK, hr->io_len);
- hr->io_len = malformed_size;
- }
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "About to check flip path UL: %s\n",
- flip_path_ul);
-
/* Upload (from the *client*) finished,
* generate curl request to the proxied service. */
if (NULL == hr->curl)
{
+ /* Malform request body. Note, this flag will be
+ * cleared only after having set the right malformed
+ * body lenght in the request headers. */
+ if (GNUNET_YES == malform_upload)
+ {
+ TALER_LOG_DEBUG
+ ("Will (badly) truncate the request.\n");
+ malformed_size = GNUNET_CRYPTO_random_u32
+ (GNUNET_CRYPTO_QUALITY_WEAK, hr->io_len);
+ hr->io_len = malformed_size;
+ }
+
if ('\0' != flip_path_ul[0])
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Going to modify the upload object (%s)\n",
hr->io_buf);
json_t *tmp;
-
tmp = json_loads (hr->io_buf,
JSON_REJECT_DUPLICATES,
NULL);
flip_object (con,
tmp,
flip_path_ul);
-
- /* No need to update 'io_length', as flipping a
+ /* No need to update 'io_len', as flipping a
* bit does not change the data size. */
hr->io_buf = json_dumps (tmp,
JSON_COMPACT);
-
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Flipped (?) upload object (%s)\n",
hr->io_buf);
-
json_decref (tmp);
}
@@ -1482,14 +1479,13 @@ create_response (void *cls,
modify_object (con, hr);
}
- body_len = hr->io_len;
- body = hr->io_buf;
if (NULL != hr->json)
{
TALER_LOG_DEBUG ("Parsing final JSON.\n");
- body = json_dumps (hr->json, JSON_COMPACT);
- body_len = strlen (body);
+ GNUNET_free (hr->io_buf);
+ hr->io_buf = json_dumps (hr->json, JSON_COMPACT);
+ hr->io_len = strlen (hr->io_buf);
json_decref (hr->json);
}
@@ -1500,17 +1496,16 @@ create_response (void *cls,
TALER_LOG_DEBUG
("Will (badly) truncate the response.\n");
fake_len = GNUNET_CRYPTO_random_u32
- (GNUNET_CRYPTO_QUALITY_WEAK, body_len);
- body_len = fake_len;
+ (GNUNET_CRYPTO_QUALITY_WEAK, hr->io_len);
+ hr->io_len = fake_len;
malform = GNUNET_NO;
}
hr->response = MHD_create_response_from_buffer
- (body_len,
- body,
+ (hr->io_len,
+ hr->io_buf,
MHD_RESPMEM_MUST_COPY);
- GNUNET_free_non_null (body);
for (header = hr->header_head;
NULL != header;
header = header->next)
@@ -1594,11 +1589,13 @@ mhd_completed_cb (void *cls,
GNUNET_free (header->value);
GNUNET_free (header);
}
+
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Finished request for %s\n",
hr->url);
+
GNUNET_free (hr->url);
- GNUNET_free_non_null (hr->io_buf);
+ GNUNET_free (hr->io_buf);
GNUNET_free (hr);
*con_cls = NULL;
}