gnunet-svn
[Top][All Lists]
Advanced

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

[gnunet] 01/04: - fixing coverity findings


From: gnunet
Subject: [gnunet] 01/04: - fixing coverity findings
Date: Tue, 25 Oct 2022 10:44:31 +0200

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

t3sserakt pushed a commit to branch master
in repository gnunet.

commit 9a52524975f49eacae04b24643b3b0da08bdf7d3
Author: t3sserakt <t3ss@posteo.de>
AuthorDate: Fri Oct 14 19:30:52 2022 +0200

    - fixing coverity findings
---
 src/testing/gnunet-cmds-helper.c                   |  2 +-
 src/testing/testing.c                              | 58 ++++++++++++----------
 src/transport/gnunet-communicator-tcp.c            |  2 +
 src/transport/gnunet-communicator-udp.c            |  1 +
 .../test_transport_plugin_cmd_simple_send.c        |  4 +-
 ...st_transport_plugin_cmd_simple_send_broadcast.c | 31 ++++++++++--
 .../test_transport_plugin_cmd_simple_send_dv.c     | 30 +++++++++--
 .../test_transport_plugin_cmd_udp_backchannel.c    | 38 ++++++++++++--
 .../transport_api_cmd_backchannel_check.c          |  9 +++-
 9 files changed, 132 insertions(+), 43 deletions(-)

diff --git a/src/testing/gnunet-cmds-helper.c b/src/testing/gnunet-cmds-helper.c
index be58f6f6a..8114d156d 100644
--- a/src/testing/gnunet-cmds-helper.c
+++ b/src/testing/gnunet-cmds-helper.c
@@ -606,7 +606,7 @@ main (int argc, char **argv)
   int i;
   size_t topology_data_length = 0;
   unsigned int read_file;
-  char cr[1] = "\n";
+  char cr[2] = "\n\0";
 
   GNUNET_log_setup ("gnunet-cmds-helper",
                     "DEBUG",
diff --git a/src/testing/testing.c b/src/testing/testing.c
index 95651830f..956820a15 100644
--- a/src/testing/testing.c
+++ b/src/testing/testing.c
@@ -2150,7 +2150,6 @@ get_node_info (unsigned int num,
          topology->nodes_x,
          topology->nodes_m,
          namespace_n);
-    hkey = GNUNET_new (struct GNUNET_ShortHashCode);
     GNUNET_CRYPTO_hash (&namespace_n, sizeof(namespace_n), &hc);
     memcpy (hkey,
             &hc,
@@ -2179,8 +2178,8 @@ get_node_info (unsigned int num,
       *namespace_ex = namespace;
       *node_connections_ex = node_connections;
     }
-    GNUNET_free (hkey);
   }
+  GNUNET_free (hkey);
 }
 
 
@@ -2442,6 +2441,7 @@ static void
 parse_ac (struct GNUNET_TESTING_NetjailNode *p_node, char *token)
 {
   char *ac_value;
+  int ret;
 
   ac_value = get_value ("AC", token);
   if (NULL != ac_value)
@@ -2449,7 +2449,13 @@ parse_ac (struct GNUNET_TESTING_NetjailNode *p_node, 
char *token)
     LOG (GNUNET_ERROR_TYPE_DEBUG,
          "ac value: %s\n",
          ac_value);
-    sscanf (ac_value, "%u", &p_node->additional_connects);
+    errno = 0;
+    ret = sscanf (ac_value, "%u", &p_node->additional_connects);
+    if (errno != 0)
+    {
+      GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "sscanf");
+    }
+    GNUNET_assert (0 < ret);
     LOG (GNUNET_ERROR_TYPE_DEBUG,
          "AC %u\n",
          p_node->additional_connects);
@@ -2481,7 +2487,6 @@ GNUNET_TESTING_get_topo_from_string (char *data)
   struct GNUNET_TESTING_NetjailTopology *topo;
   struct GNUNET_TESTING_NetjailRouter *router;
   struct GNUNET_TESTING_NetjailNamespace *namespace;
-  struct GNUNET_ShortHashCode *hkey;
   struct GNUNET_HashCode hc;
 
   token = strtok_r (data, "\n", &rest);
@@ -2552,7 +2557,8 @@ GNUNET_TESTING_get_topo_from_string (char *data)
     }
     else if (0 == strcmp (key, "K"))
     {
-      hkey = GNUNET_new (struct GNUNET_ShortHashCode);
+      struct GNUNET_ShortHashCode *hkey_k = GNUNET_new (struct
+                                                        GNUNET_ShortHashCode);
       struct GNUNET_TESTING_NetjailNode *k_node = GNUNET_new (struct
                                                               
GNUNET_TESTING_NetjailNode);
 
@@ -2564,18 +2570,18 @@ GNUNET_TESTING_get_topo_from_string (char *data)
            out);
       k_node->node_n = out;
       GNUNET_CRYPTO_hash (&out, sizeof(out), &hc);
-      memcpy (hkey,
+      memcpy (hkey_k,
               &hc,
-              sizeof (*hkey));
+              sizeof (*hkey_k));
       k_node->is_global = GNUNET_YES;
 
       if (GNUNET_YES == GNUNET_CONTAINER_multishortmap_contains (
             topo->map_globals,
-            hkey))
+            hkey_k))
         GNUNET_break (0);
       else
         GNUNET_CONTAINER_multishortmap_put (topo->map_globals,
-                                            hkey,
+                                            hkey_k,
                                             k_node,
                                             
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
       LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -2591,7 +2597,8 @@ GNUNET_TESTING_get_topo_from_string (char *data)
     }
     else if (0 == strcmp (key, "R"))
     {
-      hkey = GNUNET_new (struct GNUNET_ShortHashCode);
+      struct GNUNET_ShortHashCode *hkey_r = GNUNET_new (struct
+                                                        GNUNET_ShortHashCode);
       router = GNUNET_new (struct GNUNET_TESTING_NetjailRouter);
 
       LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -2601,9 +2608,9 @@ GNUNET_TESTING_get_topo_from_string (char *data)
            "R: %u\n",
            out);
       GNUNET_CRYPTO_hash (&out, sizeof(out), &hc);
-      memcpy (hkey,
+      memcpy (hkey_r,
               &hc,
-              sizeof (*hkey));
+              sizeof (*hkey_r));
       LOG (GNUNET_ERROR_TYPE_DEBUG,
            "Get value for key tcp_port on R.\n");
       value = get_value ("tcp_port", token);
@@ -2626,10 +2633,10 @@ GNUNET_TESTING_get_topo_from_string (char *data)
       GNUNET_free (value2);
       if (GNUNET_YES == GNUNET_CONTAINER_multishortmap_contains (
             topo->map_namespaces,
-            hkey))
+            hkey_r))
       {
         namespace = GNUNET_CONTAINER_multishortmap_get (topo->map_namespaces,
-                                                        hkey);
+                                                        hkey_r);
       }
       else
       {
@@ -2637,7 +2644,7 @@ GNUNET_TESTING_get_topo_from_string (char *data)
         namespace->namespace_n = out;
         namespace->nodes = GNUNET_CONTAINER_multishortmap_create (1,GNUNET_NO);
         GNUNET_CONTAINER_multishortmap_put (topo->map_namespaces,
-                                            hkey,
+                                            hkey_r,
                                             namespace,
                                             
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
       }
@@ -2648,7 +2655,8 @@ GNUNET_TESTING_get_topo_from_string (char *data)
     {
       struct GNUNET_TESTING_NetjailNode *p_node = GNUNET_new (struct
                                                               
GNUNET_TESTING_NetjailNode);
-      hkey = GNUNET_new (struct GNUNET_ShortHashCode);
+      struct GNUNET_ShortHashCode *hkey_p = GNUNET_new (struct
+                                                        GNUNET_ShortHashCode);
 
       LOG (GNUNET_ERROR_TYPE_DEBUG,
            "Get first Value for P.\n");
@@ -2657,16 +2665,16 @@ GNUNET_TESTING_get_topo_from_string (char *data)
            "P: %u\n",
            out);
       GNUNET_CRYPTO_hash (&out, sizeof(out), &hc);
-      memcpy (hkey,
+      memcpy (hkey_p,
               &hc,
-              sizeof (*hkey));
+              sizeof (*hkey_p));
 
       if (GNUNET_YES == GNUNET_CONTAINER_multishortmap_contains (
             topo->map_namespaces,
-            hkey))
+            hkey_p))
       {
         namespace = GNUNET_CONTAINER_multishortmap_get (topo->map_namespaces,
-                                                        hkey);
+                                                        hkey_p);
       }
       else
       {
@@ -2674,7 +2682,7 @@ GNUNET_TESTING_get_topo_from_string (char *data)
         namespace->nodes = GNUNET_CONTAINER_multishortmap_create (1,GNUNET_NO);
         namespace->namespace_n = out;
         GNUNET_CONTAINER_multishortmap_put (topo->map_namespaces,
-                                            hkey,
+                                            hkey_p,
                                             namespace,
                                             
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
       }
@@ -2685,12 +2693,12 @@ GNUNET_TESTING_get_topo_from_string (char *data)
            "P: %u\n",
            out);
       GNUNET_CRYPTO_hash (&out, sizeof(out), &hc);
-      memcpy (hkey,
+      memcpy (hkey_p,
               &hc,
-              sizeof (*hkey));
+              sizeof (*hkey_p));
       if (GNUNET_YES == GNUNET_CONTAINER_multishortmap_contains (
             namespace->nodes,
-            hkey))
+            hkey_p))
       {
         GNUNET_break (0);
       }
@@ -2698,7 +2706,7 @@ GNUNET_TESTING_get_topo_from_string (char *data)
       {
 
         GNUNET_CONTAINER_multishortmap_put (namespace->nodes,
-                                            hkey,
+                                            hkey_p,
                                             p_node,
                                             
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
         LOG (GNUNET_ERROR_TYPE_DEBUG,
diff --git a/src/transport/gnunet-communicator-tcp.c 
b/src/transport/gnunet-communicator-tcp.c
index 2a5290bf9..74c509ec5 100644
--- a/src/transport/gnunet-communicator-tcp.c
+++ b/src/transport/gnunet-communicator-tcp.c
@@ -3554,6 +3554,8 @@ run (void *cls,
   socklen_t addr_len_ipv6;
 
   (void) cls;
+  memset (&v4,0,sizeof(struct sockaddr_in));
+  memset (&v6,0,sizeof(struct sockaddr_in6));
   cfg = c;
   if (GNUNET_OK !=
       GNUNET_CONFIGURATION_get_value_string (cfg,
diff --git a/src/transport/gnunet-communicator-udp.c 
b/src/transport/gnunet-communicator-udp.c
index 07beeac38..9ca9fb90a 100644
--- a/src/transport/gnunet-communicator-udp.c
+++ b/src/transport/gnunet-communicator-udp.c
@@ -2367,6 +2367,7 @@ sock_read (void *cls)
     {
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                   "Received our own broadcast\n");
+      GNUNET_free (addr_verify);
       return;
     }
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
diff --git a/src/transport/test_transport_plugin_cmd_simple_send.c 
b/src/transport/test_transport_plugin_cmd_simple_send.c
index ee6b9669b..5941a991b 100644
--- a/src/transport/test_transport_plugin_cmd_simple_send.c
+++ b/src/transport/test_transport_plugin_cmd_simple_send.c
@@ -113,14 +113,11 @@ handle_result (void *cls,
                enum GNUNET_GenericReturnValue rv)
 {
   struct TestState *ts = cls;
-  struct GNUNET_MessageHeader *reply;
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Local test exits with status %d\n",
               rv);
 
-  reply = GNUNET_TESTING_send_local_test_finished_msg ();
-
   ts->finished_cb ();
   GNUNET_free (ts->testdir);
   GNUNET_free (ts->cfgname);
@@ -238,6 +235,7 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, 
char *router_ip,
     GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "sscanf");
   }
   GNUNET_assert (0 < sscanf_ret);
+
   if (0 == n_int)
     num = m_int;
   else
diff --git a/src/transport/test_transport_plugin_cmd_simple_send_broadcast.c 
b/src/transport/test_transport_plugin_cmd_simple_send_broadcast.c
index 6254dba36..3a282bb11 100644
--- a/src/transport/test_transport_plugin_cmd_simple_send_broadcast.c
+++ b/src/transport/test_transport_plugin_cmd_simple_send_broadcast.c
@@ -226,9 +226,14 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, 
char *router_ip,
   unsigned int num;
   struct TestState *ts = GNUNET_new (struct TestState);
   struct GNUNET_TESTING_NetjailTopology *topology;
-
+  unsigned int sscanf_ret = 0;
 
   ts->finished_cb = finished_cb;
+  LOG (GNUNET_ERROR_TYPE_ERROR,
+       "n %s m %s\n",
+       n,
+       m);
+
   if (GNUNET_YES == *read_file)
   {
     LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -240,9 +245,27 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, 
char *router_ip,
 
   ts->topology = topology;
 
-  sscanf (m, "%u", &m_int);
-  sscanf (n, "%u", &n_int);
-  sscanf (local_m, "%u", &local_m_int);
+  errno = 0;
+  sscanf_ret = sscanf (m, "%u", &m_int);
+  if (errno != 0)
+  {
+    GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "sscanf");
+  }
+  GNUNET_assert (0 < sscanf_ret);
+  errno = 0;
+  sscanf_ret = sscanf (n, "%u", &n_int);
+  if (errno != 0)
+  {
+    GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "sscanf");
+  }
+  GNUNET_assert (0 < sscanf_ret);
+  errno = 0;
+  sscanf_ret = sscanf (local_m, "%u", &local_m_int);
+  if (errno != 0)
+  {
+    GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "sscanf");
+  }
+  GNUNET_assert (0 < sscanf_ret);
 
   if (0 == n_int)
     num = m_int;
diff --git a/src/transport/test_transport_plugin_cmd_simple_send_dv.c 
b/src/transport/test_transport_plugin_cmd_simple_send_dv.c
index ea0c9aea8..8bfa1fd0a 100644
--- a/src/transport/test_transport_plugin_cmd_simple_send_dv.c
+++ b/src/transport/test_transport_plugin_cmd_simple_send_dv.c
@@ -256,8 +256,14 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, 
char *router_ip,
                            ts),
     GNUNET_MQ_handler_end ()
   };
+  unsigned int sscanf_ret = 0;
 
   ts->finished_cb = finished_cb;
+  LOG (GNUNET_ERROR_TYPE_ERROR,
+       "n %s m %s\n",
+       n,
+       m);
+
   if (GNUNET_YES == *read_file)
   {
     LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -269,9 +275,27 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, 
char *router_ip,
 
   ts->topology = topology;
 
-  sscanf (m, "%u", &m_int);
-  sscanf (n, "%u", &n_int);
-  sscanf (local_m, "%u", &local_m_int);
+  errno = 0;
+  sscanf_ret = sscanf (m, "%u", &m_int);
+  if (errno != 0)
+  {
+    GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "sscanf");
+  }
+  GNUNET_assert (0 < sscanf_ret);
+  errno = 0;
+  sscanf_ret = sscanf (n, "%u", &n_int);
+  if (errno != 0)
+  {
+    GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "sscanf");
+  }
+  GNUNET_assert (0 < sscanf_ret);
+  errno = 0;
+  sscanf_ret = sscanf (local_m, "%u", &local_m_int);
+  if (errno != 0)
+  {
+    GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "sscanf");
+  }
+  GNUNET_assert (0 < sscanf_ret);
 
   if (0 == n_int)
     num = m_int;
diff --git a/src/transport/test_transport_plugin_cmd_udp_backchannel.c 
b/src/transport/test_transport_plugin_cmd_udp_backchannel.c
index 87065e340..5a0dac32b 100644
--- a/src/transport/test_transport_plugin_cmd_udp_backchannel.c
+++ b/src/transport/test_transport_plugin_cmd_udp_backchannel.c
@@ -34,7 +34,7 @@
 /**
  * Generic logging shortcut
  */
-#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
+#define LOG(kind, ...) GNUNET_log_from (kind, "udp-backchannel", __VA_ARGS__)
 
 #define BASE_DIR "testdir"
 
@@ -187,18 +187,46 @@ start_testcase (TESTING_CMD_HELPER_write_cb 
write_message, char *router_ip,
   unsigned int num;
   struct TestState *ts = GNUNET_new (struct TestState);
   struct GNUNET_TESTING_NetjailTopology *topology;
+  unsigned int sscanf_ret = 0;
 
   ts->finished_cb = finished_cb;
+  LOG (GNUNET_ERROR_TYPE_ERROR,
+       "n %s m %s\n",
+       n,
+       m);
+
   if (GNUNET_YES == *read_file)
+  {
+    LOG (GNUNET_ERROR_TYPE_DEBUG,
+         "read from file\n");
     topology = GNUNET_TESTING_get_topo_from_file (topology_data);
+  }
   else
     topology = GNUNET_TESTING_get_topo_from_string (topology_data);
 
   ts->topology = topology;
 
-  sscanf (m, "%u", &m_int);
-  sscanf (n, "%u", &n_int);
-  sscanf (local_m, "%u", &local_m_int);
+  errno = 0;
+  sscanf_ret = sscanf (m, "%u", &m_int);
+  if (errno != 0)
+  {
+    GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "sscanf");
+  }
+  GNUNET_assert (0 < sscanf_ret);
+  errno = 0;
+  sscanf_ret = sscanf (n, "%u", &n_int);
+  if (errno != 0)
+  {
+    GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "sscanf");
+  }
+  GNUNET_assert (0 < sscanf_ret);
+  errno = 0;
+  sscanf_ret = sscanf (local_m, "%u", &local_m_int);
+  if (errno != 0)
+  {
+    GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "sscanf");
+  }
+  GNUNET_assert (0 < sscanf_ret);
 
 
   if (0 == n_int)
@@ -296,7 +324,7 @@ libgnunet_test_transport_plugin_cmd_udp_backchannel_init 
(void *cls)
 
   GNUNET_log_setup ("udp-backchannel",
                     "DEBUG",
-                    NULL);
+                    "plugin.out");
 
   api = GNUNET_new (struct GNUNET_TESTING_PluginFunctions);
   api->start_testcase = &start_testcase;
diff --git a/src/transport/transport_api_cmd_backchannel_check.c 
b/src/transport/transport_api_cmd_backchannel_check.c
index b285d7abf..bf4fe2e20 100644
--- a/src/transport/transport_api_cmd_backchannel_check.c
+++ b/src/transport/transport_api_cmd_backchannel_check.c
@@ -36,7 +36,7 @@
 /**
  * Generic logging shortcut
  */
-#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
+#define LOG(kind, ...) GNUNET_log_from (kind, "udp-backchannel",__VA_ARGS__)
 
 #define UDP "udp"
 
@@ -413,6 +413,9 @@ backchannel_check_run (void *cls,
   const struct GNUNET_TESTING_NetjailNode *node;
   const struct GNUNET_TESTING_NetjailNamespace *namespace;
 
+  LOG (GNUNET_ERROR_TYPE_DEBUG,
+       "check run 1\n");
+
   peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (is,
                                                          cs->start_peer_label);
   GNUNET_TRANSPORT_get_trait_application_handle (peer1_cmd,
@@ -429,7 +432,7 @@ backchannel_check_run (void *cls,
                                                               cs->topology);
 
   LOG (GNUNET_ERROR_TYPE_DEBUG,
-       "check run\n");
+       "check run 2\n");
 
 
   node_it = GNUNET_CONTAINER_multishortmap_iterator_create (
@@ -450,6 +453,7 @@ backchannel_check_run (void *cls,
       add_search_string (cs, node);
     }
   }
+  GNUNET_free (node_it);
   namespace_it = GNUNET_CONTAINER_multishortmap_iterator_create (
     cs->topology->map_namespaces);
   while (GNUNET_YES == GNUNET_CONTAINER_multishortmap_iterator_next (
@@ -478,6 +482,7 @@ backchannel_check_run (void *cls,
         add_search_string (cs, node);
       }
     }
+    GNUNET_free (node_it);
   }
 
   if (0 != cs->con_num)

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