From 3fe41567a6159a00656aab6319f6a744b33b85da Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 11 Jul 2021 14:39:04 +0200 Subject: -code cleanup, better error reporting --- src/json/json_helper.c | 7 +++++-- src/json/json_mhd.c | 26 ++++++++++++++++++-------- 2 files changed, 23 insertions(+), 10 deletions(-) (limited to 'src/json') diff --git a/src/json/json_helper.c b/src/json/json_helper.c index 32b262a87..6189b7596 100644 --- a/src/json/json_helper.c +++ b/src/json/json_helper.c @@ -614,8 +614,10 @@ parse_abs_time (void *cls, { tval = json_integer_value (json_t_ms); /* Time is in milliseconds in JSON, but in microseconds in GNUNET_TIME_Absolute */ - abs->abs_value_us = tval * 1000LL; - if ((abs->abs_value_us) / 1000LL != tval) + abs->abs_value_us = tval * GNUNET_TIME_UNIT_MILLISECONDS.rel_value_us; + if ((abs->abs_value_us) + / GNUNET_TIME_UNIT_MILLISECONDS.rel_value_us + != tval) { /* Integer overflow */ GNUNET_break_op (0); @@ -626,6 +628,7 @@ parse_abs_time (void *cls, if (json_is_string (json_t_ms)) { const char *val; + val = json_string_value (json_t_ms); if ((0 == strcasecmp (val, "never"))) { diff --git a/src/json/json_mhd.c b/src/json/json_mhd.c index 3a711b4f4..0b0fa0538 100644 --- a/src/json/json_mhd.c +++ b/src/json/json_mhd.c @@ -328,15 +328,25 @@ GNUNET_JSON_post_parser (size_t buffer_max, } } - *json = json_loadb (r->data, r->fill, 0, NULL); - if (NULL == *json) { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Failed to parse JSON request body\n"); - buffer_deinit (r); - GNUNET_free (r); - *con_cls = NULL; - return GNUNET_JSON_PR_JSON_INVALID; + json_error_t err; + + *json = json_loadb (r->data, + r->fill, + 0, + &err); + if (NULL == *json) + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Failed to parse JSON request body of %u byte at offset %d: %s\n", + (unsigned int) r->fill, + err.position, + err.text); + buffer_deinit (r); + GNUNET_free (r); + *con_cls = NULL; + return GNUNET_JSON_PR_JSON_INVALID; + } } buffer_deinit (r); GNUNET_free (r); -- cgit v1.2.3