- coverity 10070
authorMatthias Wachs <wachs@net.in.tum.de>
Wed, 25 Jul 2012 12:10:20 +0000 (12:10 +0000)
committerMatthias Wachs <wachs@net.in.tum.de>
Wed, 25 Jul 2012 12:10:20 +0000 (12:10 +0000)
src/transport/gnunet-service-transport_validation.c

index 40f57562adca963d4cc47bb928342ffffc4b5dc2..4dadc0f343b15c03408e92f4b9684e5c0930d693 100644 (file)
@@ -819,7 +819,7 @@ GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender,
   sig_cache = NULL;
   sig_cache_exp = NULL;
 
-  if (0 < alen)
+  if (alen > 0)
   {
     addrend = memchr (addr, '\0', alen);
     if (NULL == addrend)
@@ -890,6 +890,9 @@ GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender,
              GNUNET_h2s (&GST_my_identity.hashPubKey),
               GNUNET_i2s (sender));
 
+  /* message with structure:
+   * [TransportPongMessage][Transport name][Address] */
+
   pong = GNUNET_malloc (sizeof (struct TransportPongMessage) + alen + slen);
   pong->header.size =
       htons (sizeof (struct TransportPongMessage) + alen + slen);
@@ -931,7 +934,11 @@ GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender,
   else
   {
 #endif
-    memcpy (&((char *) &pong[1])[slen], addrend, alen);
+    if (alen > 0)
+    {
+        GNUNET_assert (NULL != addrend);
+        memcpy (&((char *) &pong[1])[slen], addrend, alen);
+    }
     if (GNUNET_TIME_absolute_get_remaining (*sig_cache_exp).rel_value <
         PONG_SIGNATURE_LIFETIME.rel_value / 4)
     {
@@ -1101,6 +1108,9 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
                             gettext_noop ("# PONG messages received"), 1,
                             GNUNET_NO);
 
+  /* message with structure:
+   * [TransportPongMessage][Transport name][Address] */
+
   pong = (const struct TransportPongMessage *) hdr;
   tname = (const char *) &pong[1];
   size = ntohs (hdr->size) - sizeof (struct TransportPongMessage);