summaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorChristian Grothoff <grothoff@gnunet.org>2023-10-13 08:50:25 +0200
committerChristian Grothoff <grothoff@gnunet.org>2023-10-13 08:50:25 +0200
commit4a8fb418d75b302ca578c5c1dec460ae9192112c (patch)
tree96f7a08b2b882bb0d20d44c9bd2cfc466cf5943f /src/util
parentc55be23e812f4add56711e1589d7aa5c9474917c (diff)
downloadexchange-4a8fb418d75b302ca578c5c1dec460ae9192112c.tar.gz
exchange-4a8fb418d75b302ca578c5c1dec460ae9192112c.tar.bz2
exchange-4a8fb418d75b302ca578c5c1dec460ae9192112c.zip
implement more sanity checks
Diffstat (limited to 'src/util')
-rw-r--r--src/util/config.c77
1 files changed, 52 insertions, 25 deletions
diff --git a/src/util/config.c b/src/util/config.c
index d3804022b..7002a6d7c 100644
--- a/src/util/config.c
+++ b/src/util/config.c
@@ -392,36 +392,63 @@ parse_currencies_cb (void *cls,
return;
}
}
-
+ if (GNUNET_OK !=
+ TALER_check_currency_scale_map (cspec->map_alt_unit_names))
{
- /* validate map only maps from decimal numbers to strings! */
- const char *str;
- json_t *val;
+ 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;
- json_object_foreach (cspec->map_alt_unit_names, str, val)
+ 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) ) )
{
- int idx;
- char dummy;
-
- if ( (1 != sscanf (str,
- "%d%c",
- &idx,
- &dummy)) ||
- (idx < -12) ||
- (idx > 24) ||
- (! json_is_string (val) ) )
- {
- 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;
- }
+ 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;
}