gnunet-svn
[Top][All Lists]
Advanced

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

[taler-exchange] branch master updated (6b48dae2 -> 4a8fb418)


From: gnunet
Subject: [taler-exchange] branch master updated (6b48dae2 -> 4a8fb418)
Date: Fri, 13 Oct 2023 08:50:28 +0200

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

grothoff pushed a change to branch master
in repository exchange.

    from 6b48dae2 -fix dist rule
     new c55be23e -add sanity check
     new 4a8fb418 implement more sanity checks

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/include/taler_util.h | 12 ++++++++++
 src/json/json_helper.c   | 20 ++++++++++++----
 src/util/config.c        | 60 ++++++++++++++++++++++++++++++++++++++++++++++--
 3 files changed, 85 insertions(+), 7 deletions(-)

diff --git a/src/include/taler_util.h b/src/include/taler_util.h
index 4dcf6f8f..5f70bf65 100644
--- a/src/include/taler_util.h
+++ b/src/include/taler_util.h
@@ -304,6 +304,18 @@ TALER_CONFIG_currency_specs_to_json (
   const struct TALER_CurrencySpecification *cspec);
 
 
+/**
+ * Check that @a map contains a valid currency scale
+ * map that maps integers from [-12,24] to currency
+ * symbols given as strings.
+ *
+ * @param map map to check
+ * @return #GNUNET_OK if @a map is valid
+ */
+enum GNUNET_GenericReturnValue
+TALER_check_currency_scale_map (const json_t *map);
+
+
 /**
  * Allow user to specify an amount on the command line.
  *
diff --git a/src/json/json_helper.c b/src/json/json_helper.c
index 99d8e5b5..6c960353 100644
--- a/src/json/json_helper.c
+++ b/src/json/json_helper.c
@@ -192,6 +192,9 @@ parse_cspec (void *cls,
   unsigned int eline;
 
   (void) cls;
+  memset (r_cspec->currency,
+          0,
+          sizeof (r_cspec->currency));
   if (GNUNET_OK !=
       GNUNET_JSON_parse (root,
                          gspec,
@@ -218,13 +221,20 @@ parse_cspec (void *cls,
     GNUNET_break_op (0);
     return GNUNET_SYSERR;
   }
-  memset (r_cspec->currency,
-          0,
-          sizeof (r_cspec->currency));
-  /* FIXME: check currency consists only of legal characters! */
+  if (GNUNET_OK !=
+      TALER_check_currency (currency))
+  {
+    GNUNET_break_op (0);
+    return GNUNET_SYSERR;
+  }
   strcpy (r_cspec->currency,
           currency);
-  /* FIXME: check map is valid! */
+  if (GNUNET_OK !=
+      TALER_check_currency_scale_map (map))
+  {
+    GNUNET_break_op (0);
+    return GNUNET_SYSERR;
+  }
   r_cspec->name = GNUNET_strdup (name);
   r_cspec->decimal_separator = GNUNET_strdup (decimal_separator);
   r_cspec->map_alt_unit_names = json_incref ((json_t *) map);
diff --git a/src/util/config.c b/src/util/config.c
index f00d11ba..7002a6d7 100644
--- a/src/util/config.c
+++ b/src/util/config.c
@@ -1,6 +1,6 @@
 /*
   This file is part of TALER
-  Copyright (C) 2014-2020 Taler Systems SA
+  Copyright (C) 2014-2023 Taler Systems SA
 
   TALER is free software; you can redistribute it and/or modify it under the
   terms of the GNU General Public License as published by the Free Software
@@ -392,7 +392,63 @@ parse_currencies_cb (void *cls,
       return;
     }
   }
-  /* FIXME: validate map only maps from decimal numbers to strings! */
+  if (GNUNET_OK !=
+      TALER_check_currency_scale_map (cspec->map_alt_unit_names))
+  {
+    GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
+                               section,
+                               "ALT_UNIT_NAMES",
+                               "invalid map entry detected");
+    cpc->failure = true;
+    json_decref (cspec->map_alt_unit_names);
+    cspec->map_alt_unit_names = NULL;
+    return;
+  }
+}
+
+
+enum GNUNET_GenericReturnValue
+TALER_check_currency_scale_map (const json_t *map)
+{
+  /* validate map only maps from decimal numbers to strings! */
+  const char *str;
+  const json_t *val;
+  bool zf = false;
+
+  if (! json_is_object (map))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                "Object required for currency scale map\n");
+    return GNUNET_SYSERR;
+  }
+  json_object_foreach ((json_t *) map, str, val)
+  {
+    int idx;
+    char dummy;
+
+    if ( (1 != sscanf (str,
+                       "%d%c",
+                       &idx,
+                       &dummy)) ||
+         (idx < -12) ||
+         (idx > 24) ||
+         (! json_is_string (val) ) )
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                  "Invalid entry `%s' in currency scale map\n",
+                  str);
+      return GNUNET_SYSERR;
+    }
+    if (0 == idx)
+      zf = true;
+  }
+  if (! zf)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                "Entry for 0 missing in currency scale map\n");
+    return GNUNET_SYSERR;
+  }
+  return GNUNET_OK;
 }
 
 

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

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