gnunet-svn
[Top][All Lists]
Advanced

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

[gnunet] branch master updated: -code cleanup, better error reporting


From: gnunet
Subject: [gnunet] branch master updated: -code cleanup, better error reporting
Date: Sun, 11 Jul 2021 14:42:18 +0200

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

grothoff pushed a commit to branch master
in repository gnunet.

The following commit(s) were added to refs/heads/master by this push:
     new 3fe41567a -code cleanup, better error reporting
3fe41567a is described below

commit 3fe41567a6159a00656aab6319f6a744b33b85da
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Sun Jul 11 14:39:04 2021 +0200

    -code cleanup, better error reporting
---
 src/json/json_helper.c |  7 +++++--
 src/json/json_mhd.c    | 26 ++++++++++++++++++--------
 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,
   {
     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);

-- 
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]