fix potential use after free in tcp
authorChristian Grothoff <christian@grothoff.org>
Fri, 5 Jan 2018 19:53:20 +0000 (20:53 +0100)
committerChristian Grothoff <christian@grothoff.org>
Fri, 5 Jan 2018 19:53:45 +0000 (20:53 +0100)
src/transport/tcp_connection_legacy.c
src/transport/tcp_server_legacy.c

index 5b219a467c1966d14332bfed33b53a625ced0f0b..17157436dc2fe5fcb64a8e7c1e8405157fdb494e 100644 (file)
@@ -1218,8 +1218,10 @@ RETRY:
  * @param timeout maximum amount of time to wait
  * @param receiver function to call with received data
  * @param receiver_cls closure for @a receiver
+ * @return #GNUNET_SYSERR if @a connection died (receiver was
+ *          called with error)
  */
-void
+int
 GNUNET_CONNECTION_receive (struct GNUNET_CONNECTION_Handle *connection,
                            size_t max,
                            struct GNUNET_TIME_Relative timeout,
@@ -1241,7 +1243,7 @@ GNUNET_CONNECTION_receive (struct GNUNET_CONNECTION_Handle *connection,
                                      connection->sock,
                                      &receive_ready,
                                      connection);
-    return;
+    return GNUNET_OK;
   }
   if ((NULL == connection->dns_active) &&
       (NULL == connection->ap_head) &&
@@ -1252,8 +1254,9 @@ GNUNET_CONNECTION_receive (struct GNUNET_CONNECTION_Handle *connection,
              NULL, 0,
              NULL, 0,
              ETIMEDOUT);
-    return;
+    return GNUNET_SYSERR;
   }
+  return GNUNET_OK;
 }
 
 
index d0ce790fcc3f576ab14df80d4e21c6d55f5d0b48..f75b41e8ca2fde4b195c5eae9fd97bef4b5b3a19 100644 (file)
@@ -1044,11 +1044,13 @@ process_mst (struct GNUNET_SERVER_Client *client,
            "Server re-enters receive loop, timeout: %s.\n",
            GNUNET_STRINGS_relative_time_to_string (client->idle_timeout, GNUNET_YES));
       client->receive_pending = GNUNET_YES;
-      GNUNET_CONNECTION_receive (client->connection,
-                                 GNUNET_MAX_MESSAGE_SIZE - 1,
-                                 client->idle_timeout,
-                                 &process_incoming,
-                                 client);
+      if (GNUNET_OK !=
+         GNUNET_CONNECTION_receive (client->connection,
+                                    GNUNET_MAX_MESSAGE_SIZE - 1,
+                                    client->idle_timeout,
+                                    &process_incoming,
+                                    client))
+       return;
       break;
     }
     LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -1287,11 +1289,13 @@ GNUNET_SERVER_connect_socket (struct GNUNET_SERVER_Handle *server,
   for (n = server->connect_notify_list_head; NULL != n; n = n->next)
     n->callback (n->callback_cls, client);
   client->receive_pending = GNUNET_YES;
-  GNUNET_CONNECTION_receive (client->connection,
-                             GNUNET_MAX_MESSAGE_SIZE - 1,
-                             client->idle_timeout,
-                             &process_incoming,
-                             client);
+  if (GNUNET_SYSERR ==
+      GNUNET_CONNECTION_receive (client->connection,
+                                GNUNET_MAX_MESSAGE_SIZE - 1,
+                                client->idle_timeout,
+                                &process_incoming,
+                                client))
+    return NULL;
   return client;
 }