codesonar fixes
authorNathan S. Evans <evans@in.tum.de>
Mon, 21 Jun 2010 14:30:08 +0000 (14:30 +0000)
committerNathan S. Evans <evans@in.tum.de>
Mon, 21 Jun 2010 14:30:08 +0000 (14:30 +0000)
src/testing/testing.c
src/testing/testing_group.c

index 5b36fc3803ff5697b13d09410db8c192ad9bb9c7..58d09806b8acf7cf1fdbc792ca9b2a9c9a0cefe4 100644 (file)
@@ -65,6 +65,7 @@ static void
 process_hello (void *cls, const struct GNUNET_MessageHeader *message)
 {
   struct GNUNET_TESTING_Daemon *daemon = cls;
+  int msize;
   if (daemon == NULL)
     return;
 
@@ -75,6 +76,11 @@ process_hello (void *cls, const struct GNUNET_MessageHeader *message)
     }
 
   GNUNET_assert (message != NULL);
+  msize = ntohs(message->size);
+  if (msize < 1)
+    {
+      return;
+    }
   if (daemon->th != NULL)
     {
       GNUNET_TRANSPORT_get_hello_cancel(daemon->th, &process_hello, daemon);
@@ -85,14 +91,18 @@ process_hello (void *cls, const struct GNUNET_MessageHeader *message)
               "HELLO", GNUNET_i2s (&daemon->id));
 #endif
 
-  GNUNET_free_non_null(daemon->hello);
-  daemon->hello = GNUNET_malloc(ntohs(message->size));
-  memcpy(daemon->hello, message, ntohs(message->size));
 
-  if (daemon->th != NULL)
+
     {
-      GNUNET_TRANSPORT_disconnect(daemon->th);
-      daemon->th = NULL;
+      GNUNET_free_non_null(daemon->hello);
+      daemon->hello = GNUNET_malloc(msize);
+      memcpy(daemon->hello, message, msize);
+
+      if (daemon->th != NULL)
+        {
+          GNUNET_TRANSPORT_disconnect(daemon->th);
+          daemon->th = NULL;
+        }
     }
 
 }
index b304047baad9b3eac3a6bedce31027bfadb04b42..de624f25fa92781fa9aca4799f57942a621d603a 100644 (file)
@@ -3150,6 +3150,8 @@ GNUNET_TESTING_daemons_churn (struct GNUNET_TESTING_PeerGroup *pg,
   struct ChurnContext *churn_ctx;
   unsigned int running;
   unsigned int stopped;
+  unsigned int total_running;
+  unsigned int total_stopped;
   unsigned int i;
   unsigned int *running_arr;
   unsigned int *stopped_arr;
@@ -3194,8 +3196,14 @@ GNUNET_TESTING_daemons_churn (struct GNUNET_TESTING_PeerGroup *pg,
   }
 
   churn_ctx = GNUNET_malloc(sizeof(struct ChurnContext));
-  running_arr = GNUNET_malloc(running * sizeof(unsigned int));
-  stopped_arr = GNUNET_malloc(stopped * sizeof(unsigned int));
+
+  running_arr = NULL;
+  if (running > 0)
+    running_arr = GNUNET_malloc(running * sizeof(unsigned int));
+
+  stopped_arr = NULL;
+  if (stopped > 0)
+    stopped_arr = GNUNET_malloc(stopped * sizeof(unsigned int));
 
   running_permute = NULL;
   stopped_permute = NULL;
@@ -3205,6 +3213,8 @@ GNUNET_TESTING_daemons_churn (struct GNUNET_TESTING_PeerGroup *pg,
   if (stopped > 0)
     stopped_permute = GNUNET_CRYPTO_random_permute(GNUNET_CRYPTO_QUALITY_WEAK, stopped);
 
+  total_running = running;
+  total_stopped = stopped;
   running = 0;
   stopped = 0;
 
@@ -3217,11 +3227,13 @@ GNUNET_TESTING_daemons_churn (struct GNUNET_TESTING_PeerGroup *pg,
   {
     if (pg->peers[i].daemon->running == GNUNET_YES)
     {
+      GNUNET_assert((running_arr != NULL) && (total_running > running));
       running_arr[running] = i;
       running++;
     }
     else
     {
+      GNUNET_assert((stopped_arr != NULL) && (total_stopped > stopped));
       stopped_arr[stopped] = i;
       stopped++;
     }
@@ -3247,8 +3259,8 @@ GNUNET_TESTING_daemons_churn (struct GNUNET_TESTING_PeerGroup *pg,
                                          timeout, &churn_start_callback, churn_ctx);
   }
 
-  GNUNET_free(running_arr);
-  GNUNET_free(stopped_arr);
+  GNUNET_free_non_null(running_arr);
+  GNUNET_free_non_null(stopped_arr);
   GNUNET_free_non_null(running_permute);
   GNUNET_free_non_null(stopped_permute);
 }