fix #4985
authorChristian Grothoff <christian@grothoff.org>
Tue, 11 Apr 2017 09:37:46 +0000 (11:37 +0200)
committerChristian Grothoff <christian@grothoff.org>
Tue, 11 Apr 2017 09:37:46 +0000 (11:37 +0200)
src/cadet/cadet_api.c
src/conversation/gnunet-service-conversation.c
src/include/gnunet_cadet_service.h
src/include/gnunet_disk_lib.h
src/util/strings.c

index decf473a9c11679bf0811eabcfb907e042ac5613..3fdeffe13089a9680ef713afb29faa4f929096d1 100644 (file)
@@ -1583,7 +1583,7 @@ GNUNET_CADET_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
  * @param window_changes Function called when the transmit window size changes.
  * @param disconnects Function called when a channel is disconnected.
  * @param handlers Callbacks for messages we care about, NULL-terminated.
- * @return Port handle.
+ * @return Port handle, NULL if port is in use
  */
 struct GNUNET_CADET_Port *
 GNUNET_CADET_open_port (struct GNUNET_CADET_Handle *h,
@@ -1604,17 +1604,21 @@ GNUNET_CADET_open_port (struct GNUNET_CADET_Handle *h,
   p = GNUNET_new (struct GNUNET_CADET_Port);
   p->cadet = h;
   p->id = *port;
+  if (GNUNET_OK !=
+      GNUNET_CONTAINER_multihashmap_put (h->ports,
+                                         &p->id,
+                                         p,
+                                         GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
+  {
+    GNUNET_free (p);
+    return NULL;
+  }
   p->connects = connects;
   p->cls = connects_cls;
   p->window_changes = window_changes;
   p->disconnects = disconnects;
   p->handlers = GNUNET_MQ_copy_handlers (handlers);
 
-  GNUNET_assert (GNUNET_OK ==
-                GNUNET_CONTAINER_multihashmap_put (h->ports,
-                                                   &p->id,
-                                                   p,
-                                                   GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
 
   env = GNUNET_MQ_msg (msg,
                        GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_OPEN);
index 5f43bfe80d46c64a97ede40f86f9197a354b9f31..7d319e51e1568c8cf10dc0b0a4a95ae4c3187571 100644 (file)
@@ -1270,6 +1270,14 @@ handle_client_register_message (void *cls,
                                        NULL,
                                        &inbound_end,
                                        cadet_handlers);
+  if (NULL == line->port)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                _("Could not open line, port %s already in use!\n"),
+                GNUNET_h2s (&msg->line_port));
+    GNUNET_SERVICE_client_drop (line->client);
+    return;
+  }
   GNUNET_SERVICE_client_continue (line->client);
 }
 
index f76f17a518eb67e9b5962492a386d7bcda9b32da..e2edbcc2cb4ff7123ed30b9b71b32672aaaa9ffd 100644 (file)
@@ -221,7 +221,7 @@ GNUNET_CADET_disconnect (struct GNUNET_CADET_Handle *handle);
  *                       Can be NULL.
  * @param disconnects Function called when a channel is disconnected.
  * @param handlers Callbacks for messages we care about, NULL-terminated.
- * @return Port handle.
+ * @return Port handle, NULL if port is in use
  */
 struct GNUNET_CADET_Port *
 GNUNET_CADET_open_port (struct GNUNET_CADET_Handle *h,
index 02c4b3674f787f9a3bd2711262a72a4f42928a92..be28854600c1f6c27deaff9ba55118d643b67415 100644 (file)
@@ -331,7 +331,8 @@ GNUNET_DISK_file_seek (const struct GNUNET_DISK_FileHandle *h, off_t offset,
  * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
  */
 int
-GNUNET_DISK_file_size (const char *filename, uint64_t *size,
+GNUNET_DISK_file_size (const char *filename,
+                       uint64_t *size,
                        int include_symbolic_links,
                        int single_file_mode);
 
index d3268f4d99fa70d23a56db782a4d53f2c5fb80d4..f554a9e83194cd2e393f8fcd4506e756370c3171 100644 (file)
@@ -818,6 +818,7 @@ GNUNET_STRINGS_get_short_name (const char *filename)
 {
   const char *short_fn = filename;
   const char *ss;
+
   while (NULL != (ss = strstr (short_fn, DIR_SEPARATOR_STR))
       && (ss[1] != '\0'))
     short_fn = 1 + ss;