aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2021-07-11 14:39:04 +0200
committerChristian Grothoff <christian@grothoff.org>2021-07-11 14:39:10 +0200
commit3fe41567a6159a00656aab6319f6a744b33b85da (patch)
tree347bc65baf56e198cdca252bb9427550ed308edb
parent097d7e3c2cc0534486332733fe291d11a332609c (diff)
downloadgnunet-3fe41567a6159a00656aab6319f6a744b33b85da.tar.gz
gnunet-3fe41567a6159a00656aab6319f6a744b33b85da.zip
-code cleanup, better error reporting
-rw-r--r--src/json/json_helper.c7
-rw-r--r--src/json/json_mhd.c26
2 files changed, 23 insertions, 10 deletions
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,
614 { 614 {
615 tval = json_integer_value (json_t_ms); 615 tval = json_integer_value (json_t_ms);
616 /* Time is in milliseconds in JSON, but in microseconds in GNUNET_TIME_Absolute */ 616 /* Time is in milliseconds in JSON, but in microseconds in GNUNET_TIME_Absolute */
617 abs->abs_value_us = tval * 1000LL; 617 abs->abs_value_us = tval * GNUNET_TIME_UNIT_MILLISECONDS.rel_value_us;
618 if ((abs->abs_value_us) / 1000LL != tval) 618 if ((abs->abs_value_us)
619 / GNUNET_TIME_UNIT_MILLISECONDS.rel_value_us
620 != tval)
619 { 621 {
620 /* Integer overflow */ 622 /* Integer overflow */
621 GNUNET_break_op (0); 623 GNUNET_break_op (0);
@@ -626,6 +628,7 @@ parse_abs_time (void *cls,
626 if (json_is_string (json_t_ms)) 628 if (json_is_string (json_t_ms))
627 { 629 {
628 const char *val; 630 const char *val;
631
629 val = json_string_value (json_t_ms); 632 val = json_string_value (json_t_ms);
630 if ((0 == strcasecmp (val, "never"))) 633 if ((0 == strcasecmp (val, "never")))
631 { 634 {
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,
328 } 328 }
329 } 329 }
330 330
331 *json = json_loadb (r->data, r->fill, 0, NULL);
332 if (NULL == *json)
333 { 331 {
334 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 332 json_error_t err;
335 "Failed to parse JSON request body\n"); 333
336 buffer_deinit (r); 334 *json = json_loadb (r->data,
337 GNUNET_free (r); 335 r->fill,
338 *con_cls = NULL; 336 0,
339 return GNUNET_JSON_PR_JSON_INVALID; 337 &err);
338 if (NULL == *json)
339 {
340 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
341 "Failed to parse JSON request body of %u byte at offset %d: %s\n",
342 (unsigned int) r->fill,
343 err.position,
344 err.text);
345 buffer_deinit (r);
346 GNUNET_free (r);
347 *con_cls = NULL;
348 return GNUNET_JSON_PR_JSON_INVALID;
349 }
340 } 350 }
341 buffer_deinit (r); 351 buffer_deinit (r);
342 GNUNET_free (r); 352 GNUNET_free (r);