commit 050fb32d5336bc957e45cbfa3e4b66411a9a8062
parent 45ae2b1b2520b510be0908614afb36d7fefe2fea
Author: Christian Grothoff <grothoff@gnunet.org>
Date: Fri, 14 Aug 2026 22:18:56 +0200
do not leave amount half-initialize on failure
Diffstat:
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/src/util/amount.c b/src/util/amount.c
@@ -43,6 +43,7 @@ enum GNUNET_GenericReturnValue
TALER_check_currency (const char *str)
{
size_t len = strlen (str);
+
if (len >= TALER_CURRENCY_LEN)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -104,15 +105,21 @@ TALER_string_to_amount (const char *str,
}
GNUNET_assert (TALER_CURRENCY_LEN > (colon - str));
- for (unsigned int i = 0; i<colon - str; i++)
- amount->currency[i] = str[i];
+ memcpy (&amount->currency[0],
+ str,
+ colon - str);
/* 0-terminate *and* normalize buffer by setting everything to '\0' */
memset (&amount->currency [colon - str],
0,
TALER_CURRENCY_LEN - (colon - str));
if (GNUNET_OK !=
TALER_check_currency (amount->currency))
+ {
+ memset (&amount->currency[0],
+ 0,
+ colon - str);
return GNUNET_SYSERR;
+ }
/* skip colon */
value = colon + 1;
if ('\0' == value[0])