summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2023-07-13 12:10:41 +0200
committerChristian Grothoff <christian@grothoff.org>2023-07-13 12:10:41 +0200
commitf121504c0765ac00872ae44afbeed36bcc79ccf7 (patch)
treea3cfb68bb64d2788efed208896c1002bfe775db9
parent5882da27735157ae1c85bfb6fdb660fbc254d7e8 (diff)
downloadtwister-f121504c0765ac00872ae44afbeed36bcc79ccf7.tar.gz
twister-f121504c0765ac00872ae44afbeed36bcc79ccf7.tar.bz2
twister-f121504c0765ac00872ae44afbeed36bcc79ccf7.zip
replace use of deprecated CURLOPT_PUT, make twisting base32-encoded strings more reliable
-rw-r--r--src/twister/taler-twister-service.c90
1 files changed, 46 insertions, 44 deletions
diff --git a/src/twister/taler-twister-service.c b/src/twister/taler-twister-service.c
index 88910d4..e8d6204 100644
--- a/src/twister/taler-twister-service.c
+++ b/src/twister/taler-twister-service.c
@@ -1166,20 +1166,28 @@ perform_modbody:
* @param flip_path the path to the string-field to flip.
* @return #GNUNET_OK when the path was found, and flipped.
*/
-static int
+static enum GNUNET_GenericReturnValue
flip_object (struct MHD_Connection *con,
json_t *json,
- char *flip_path)
+ const char *flip_path)
{
char *target;
json_t *parent;
- #define CROCKFORD_MAX_INDEX 31
- char crockford_chars[] = {'0', '1', '2', '3', '4', '5',
- '6', '7', '8', '9', 'A', 'B',
- 'C', 'D', 'E', 'F', 'G', 'H',
- 'J', 'K', 'M', 'N', 'P', 'Q',
- 'R', 'S', 'T', 'V', 'W', 'X',
- 'Y', 'Z'}; // index: 0-31
+ json_t *child = NULL;
+ const char *current_value;
+ char *current_value_flip;
+ unsigned int crockford_index;
+ unsigned int flip_index;
+ size_t len;
+ const char crockford_chars[] = {
+ '0', '1', '2', '3', '4', '5',
+ '6', '7', '8', '9', 'A', 'B',
+ 'C', 'D', 'E', 'F', 'G', 'H',
+ 'J', 'K', 'M', 'N', 'P', 'Q',
+ 'R', 'S', 'T', 'V', 'W', 'X',
+ 'Y', 'Z'
+ }; /* index: 0-31 */
+#define CROCKFORD_MAX_INDEX (sizeof (crockford_chars))
if (NULL == json)
return GNUNET_NO;
@@ -1197,63 +1205,60 @@ flip_object (struct MHD_Connection *con,
return GNUNET_NO;
}
- /* here, element is the parent of the element to be deleted. */
- json_t *child = NULL;
- const char *current_value;
- char *current_value_flip;
- uint32_t crockford_index;
- uint32_t flip_index;
if (json_is_object (parent))
- child = json_object_get (parent, target);
-
+ child = json_object_get (parent,
+ target);
if (json_is_array (parent))
- child = json_array_get
- (parent, (unsigned int) strtoul (target,
- NULL,
- 10));
-
+ child = json_array_get (parent,
+ (unsigned int) strtoul (target,
+ NULL,
+ 10));
/* json walker is such that at this point the
* child's parent is always a object or array. */
GNUNET_assert (NULL != child);
+ GNUNET_free (target);
current_value = json_string_value (child);
-
+ if (NULL == current_value)
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
current_value_flip = GNUNET_strdup (current_value);
-
- flip_index = GNUNET_CRYPTO_random_u32
- (GNUNET_CRYPTO_QUALITY_WEAK,
- strlen (current_value_flip));
+ len = strlen (current_value_flip);
+ if (len > 1)
+ len--; /* do NOT flip last character, as that
+ one may not matter in base32 encoding */
do {
- crockford_index = GNUNET_CRYPTO_random_u32
- (GNUNET_CRYPTO_QUALITY_STRONG,
- CROCKFORD_MAX_INDEX + 1);
-
+ flip_index = GNUNET_CRYPTO_random_u32 (
+ GNUNET_CRYPTO_QUALITY_WEAK,
+ len);
+ crockford_index = GNUNET_CRYPTO_random_u32 (
+ GNUNET_CRYPTO_QUALITY_STRONG,
+ CROCKFORD_MAX_INDEX);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Try flipping with Crockford index: %u\n",
+ "Try flipping %u to Crockford index: %u\n",
+ flip_index,
crockford_index);
}
while (current_value_flip[flip_index] ==
crockford_chars[crockford_index]);
-
current_value_flip[flip_index] =
crockford_chars[crockford_index];
TWISTER_LOG_INFO ("Flipping %s to %s\n",
current_value,
current_value_flip);
- if (0 != json_string_set
- (child,
- (const char *) current_value_flip))
+ if (0 != json_string_set (child,
+ current_value_flip))
{
- TWISTER_LOG_WARNING ("Could not flip '%s'\n", target);
+ TWISTER_LOG_WARNING ("Could not flip '%s'\n",
+ flip_path);
GNUNET_free (current_value_flip);
- GNUNET_free (target);
return GNUNET_SYSERR;
}
-
GNUNET_free (current_value_flip);
- GNUNET_free (target);
return GNUNET_OK;
}
@@ -1735,19 +1740,16 @@ create_response (void *cls,
"Crafting a CURL PUT request\n");
curl_easy_setopt (hr->curl,
- CURLOPT_PUT,
+ CURLOPT_UPLOAD,
1L);
-
hr->state = REQUEST_STATE_PROXY_UPLOAD_STARTED;
}
else if (0 == strcasecmp (meth,
MHD_HTTP_METHOD_POST))
{
-
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Crafting a CURL POST request\n");
-
curl_easy_setopt (hr->curl,
CURLOPT_POST,
1L);