social: leaks and untreated error conditions
authorCarlo von lynX <lynX@time.to.get.psyced.org>
Thu, 28 Jul 2016 00:22:43 +0000 (00:22 +0000)
committerCarlo von lynX <lynX@time.to.get.psyced.org>
Thu, 28 Jul 2016 00:22:43 +0000 (00:22 +0000)
src/social/gnunet-service-social.c
src/social/gnunet-social.c
src/social/social_api.c

index eca1b14d71a6e4245181e00459fb9a675c51df15..e499130d4800ce64431d3991793515a83a6b19c8 100644 (file)
@@ -809,6 +809,8 @@ host_relay_message_part (struct Host *hst,
   if (GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_METHOD == ptype)
   {
     /* FIXME: last message was unfinished, cancel & remove from queue */
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+               "FIXME: last message was unfinished.\n");
   }
 
   tmit_msg = psyc_transmit_queue_message (&hst->plc, NULL, ntohs (pmsg->size),
@@ -817,12 +819,14 @@ host_relay_message_part (struct Host *hst,
   switch (ptype)
   {
   case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_METHOD:
-    GNUNET_CONTAINER_multihashmap_put (hst->relay_msgs, &nym_pub_hash, tmit_msg,
-                                       GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
+    GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multihashmap_put
+                                     (hst->relay_msgs, &nym_pub_hash, tmit_msg,
+                                       GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
     break;
   case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_END:
   case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_CANCEL:
-    GNUNET_CONTAINER_multihashmap_remove (hst->relay_msgs, &nym_pub_hash, tmit_msg);
+    GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove
+                                    (hst->relay_msgs, &nym_pub_hash, tmit_msg));
     break;
   }
 }
@@ -985,17 +989,23 @@ place_recv_save_data (void *cls,
                    place_pub_str, DIR_SEPARATOR,
                    GNUNET_ntohll (msg->message_id));
   GNUNET_free (place_pub_str);
-  GNUNET_DISK_directory_create_for_file (filename);
+  if (GNUNET_SYSERR == GNUNET_DISK_directory_create_for_file (filename))
+  {
+    GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "create", filename);
+    GNUNET_free (filename);
+    return;
+  }
+
   struct GNUNET_DISK_FileHandle *
     fh = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_WRITE,
                                 GNUNET_DISK_PERM_NONE);
   if (NULL != fh)
   {
     if (plc->file_offset != GNUNET_DISK_file_seek
-         (fh, plc->file_offset, GNUNET_DISK_SEEK_SET)) {
-        GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "seek", filename);
-       GNUNET_free (filename);
-       return;
+                           (fh, plc->file_offset, GNUNET_DISK_SEEK_SET)) {
+      GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "seek", filename);
+      GNUNET_free (filename);
+      return;
     }
     GNUNET_DISK_file_write (fh, data, data_size);
     GNUNET_DISK_file_close (fh);
index 68a45bd5eb057ff49a6ea2e0475bb455f4783d5b..ab08c90f849f91616ac7780c38ff3713bfb79a7e 100644 (file)
@@ -727,12 +727,13 @@ guest_enter (const struct GNUNET_CRYPTO_EddsaPublicKey *pub_key,
     return;
   }
 
+  struct GNUNET_PSYC_Message *join_msg = guest_enter_msg_create ();
   gst = GNUNET_SOCIAL_guest_enter (app, ego, pub_key,
                                    GNUNET_PSYC_SLAVE_JOIN_NONE,
-                                   peer, 0, NULL, guest_enter_msg_create (),
-                                   slicer_create (),
+                                   peer, 0, NULL, join_msg, slicer_create (),
                                    guest_recv_local_enter,
                                    guest_recv_entry_decision, NULL);
+  GNUNET_free (join_msg);
   plc = GNUNET_SOCIAL_guest_get_place (gst);
 }
 
@@ -746,10 +747,12 @@ guest_enter_by_name (const char *gns_name)
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Entering to place by name as guest.\n");
 
+  struct GNUNET_PSYC_Message *join_msg = guest_enter_msg_create ();
   gst = GNUNET_SOCIAL_guest_enter_by_name (app, ego, gns_name, NULL,
-                                           guest_enter_msg_create (), slicer,
+                                           join_msg, slicer,
                                            guest_recv_local_enter,
                                            guest_recv_entry_decision, NULL);
+  GNUNET_free (join_msg);
   plc = GNUNET_SOCIAL_guest_get_place (gst);
 }
 
@@ -1157,9 +1160,17 @@ run (void *cls, char *const *args, const char *cfgfile,
 
   if (opt_ego)
   {
-    GNUNET_CRYPTO_ecdsa_public_key_from_string (opt_ego,
+    if (GNUNET_OK !=
+        GNUNET_CRYPTO_ecdsa_public_key_from_string (opt_ego,
                                                 strlen (opt_ego),
-                                                &ego_pub_key);
+                                                &ego_pub_key))
+    {
+      FPRINTF (stderr,
+               _("Public key `%s' malformed\n"),
+               opt_ego);
+      exit_fail ();
+      return;
+    }
   }
 
   core = GNUNET_CORE_connect (cfg, NULL, &core_connected, NULL, NULL,
index c33f39dceab8ad932eb5203d6763e13b3ae79efc..a7a4e9dcf59f052a17fc01040b539ecc8f3c5e48 100644 (file)
@@ -967,19 +967,21 @@ app_recv_place (void *cls,
 
   if (GNUNET_YES == pmsg->is_host)
   {
-    struct GNUNET_SOCIAL_HostConnection *hconn = GNUNET_malloc (sizeof (*hconn));
-    hconn->app = app;
-    hconn->plc_msg = *pmsg;
-    if (NULL != app->host_cb)
+    if (NULL != app->host_cb) {
+      struct GNUNET_SOCIAL_HostConnection *hconn = GNUNET_malloc (sizeof (*hconn));
+      hconn->app = app;
+      hconn->plc_msg = *pmsg;
       app->host_cb (app->cb_cls, hconn, ego, &pmsg->place_pub_key, pmsg->place_state);
+      // FIXME: should this have a GNUNET_free (hconn) here?
+    }
   }
-  else
+  else if (NULL != app->guest_cb)
   {
     struct GNUNET_SOCIAL_GuestConnection *gconn = GNUNET_malloc (sizeof (*gconn));
     gconn->app = app;
     gconn->plc_msg = *pmsg;
-    if (NULL != app->guest_cb)
-      app->guest_cb (app->cb_cls, gconn, ego, &pmsg->place_pub_key, pmsg->place_state);
+    app->guest_cb (app->cb_cls, gconn, ego, &pmsg->place_pub_key, pmsg->place_state);
+    GNUNET_free (gconn); // FIXME: is this correct here?
   }
 }