commit 8d7076f423d3909068c2f79cadcec37a033d4e6a
parent 8b914fd9ccff92a7db4009a58c2fccfefaba11d9
Author: Marcello Stanisci <stanisci.m@gmail.com>
Date: Sat, 10 Mar 2018 14:37:20 +0100
fix last path token detection.
The object walker now checks if the last path's token
does exist in the parent object, before returning to
the caller.
Diffstat:
1 file changed, 21 insertions(+), 3 deletions(-)
diff --git a/src/twister/taler-twister-service.c b/src/twister/taler-twister-service.c
@@ -880,6 +880,22 @@ walk_response_object (const char *path,
return GNUNET_NO;
}
+ if ( (NULL == json_object_get (element,
+ last_token) ) &&
+ /* NOTE: if token is bad but converts to either 0, or
+ * ULONG max AND the array has such a index, then this
+ * test won't detect any error. Likewise, the method for
+ * deleting/modifying the response will operate on that
+ * same random array element. */
+ (NULL == json_array_get (element, (unsigned int) strtoul
+ (token, NULL, 10))) )
+ {
+ TALER_LOG_WARNING ("(Last) path token '%s' not found",
+ last_token);
+ GNUNET_free (path_dup);
+ return GNUNET_NO;
+ }
+
*target = GNUNET_strdup (last_token);
*parent = element;
GNUNET_free (path_dup);
@@ -927,14 +943,15 @@ modify_object (struct MHD_Connection *con,
TALER_LOG_ERROR ("Unvalid new value given: %s\n", modify_value);
modify_path[0] = '\0';
GNUNET_free (target);
+ json_decref (new_value);
return;
perform_modbody:
ret_modify = -1;
if (json_is_object (parent))
- ret_modify = json_object_set_new (parent,
- target,
- new_value);
+ ret_modify = json_object_set (parent,
+ target,
+ new_value);
if (json_is_array (parent))
ret_modify = json_array_set_new
(parent,
@@ -945,6 +962,7 @@ modify_object (struct MHD_Connection *con,
modify_path[0] = '\0';
GNUNET_free (target);
+ json_decref (new_value);
return;
}