gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libmicrohttpd] branch master updated (6cb3cc34 -> bfa7c5a1)


From: gnunet
Subject: [libmicrohttpd] branch master updated (6cb3cc34 -> bfa7c5a1)
Date: Thu, 16 Nov 2023 08:04:43 +0100

This is an automated email from the git hooks/post-receive script.

karlson2k pushed a change to branch master
in repository libmicrohttpd.

    from 6cb3cc34 Fixed (again) and improved detection of application-provided 
socket type
     new 89021a86 MHD_start_daemon(): added check for app-provided socket to 
fit fd_set
     new bfa7c5a1 MHD_start_daemon(): fixed leaked listen socket when daemon 
start failed

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/microhttpd/daemon.c | 103 ++++++++++++++++++++++++++++++------------------
 1 file changed, 64 insertions(+), 39 deletions(-)

diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index e97ddb91..5cca4797 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -7546,7 +7546,7 @@ MHD_start_daemon_va (unsigned int flags,
 {
   const MHD_SCKT_OPT_BOOL_ on = 1;
   struct MHD_Daemon *daemon;
-  MHD_socket listen_fd;
+  MHD_socket listen_fd = MHD_INVALID_SOCKET;
   const struct sockaddr *pservaddr = NULL;
   socklen_t addrlen;
 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
@@ -8143,6 +8143,7 @@ MHD_start_daemon_va (unsigned int flags,
                 (int) MHD_D_GET_FD_SETSIZE_ (daemon));
 #endif
       MHD_socket_close_chk_ (listen_fd);
+      listen_fd = MHD_INVALID_SOCKET;
       goto free_and_fail;
     }
 
@@ -8292,6 +8293,7 @@ MHD_start_daemon_va (unsigned int flags,
                 MHD_socket_last_strerr_ ());
 #endif
       MHD_socket_close_chk_ (listen_fd);
+      listen_fd = MHD_INVALID_SOCKET;
       goto free_and_fail;
     }
 #ifdef TCP_FASTOPEN
@@ -8322,62 +8324,78 @@ MHD_start_daemon_va (unsigned int flags,
                 MHD_socket_last_strerr_ ());
 #endif
       MHD_socket_close_chk_ (listen_fd);
+      listen_fd = MHD_INVALID_SOCKET;
       goto free_and_fail;
     }
   }
   else
   {
+    if (MHD_D_IS_USING_SELECT_ (daemon) &&
+        (! MHD_D_DOES_SCKT_FIT_FDSET_ (daemon->listen_fd, daemon)) )
+    {
+#ifdef HAVE_MESSAGES
+      MHD_DLOG (daemon,
+                _ ("Listen socket descriptor (%d) is not " \
+                   "less than daemon FD_SETSIZE value (%d).\n"),
+                (int) daemon->listen_fd,
+                (int) MHD_D_GET_FD_SETSIZE_ (daemon));
+#endif
+      goto free_and_fail;
+    }
+    else
+    {
 #if defined(SOL_SOCKET) && (defined(SO_DOMAIN) || defined(SO_PROTOCOL_INFOW))
-    int af;
-    int opt_name;
-    void *poptval;
-    socklen_t optval_size;
+      int af;
+      int opt_name;
+      void *poptval;
+      socklen_t optval_size;
 #ifdef SO_DOMAIN
-    opt_name = SO_DOMAIN;
-    poptval = ⁡
-    optval_size = (socklen_t) sizeof (af);
+      opt_name = SO_DOMAIN;
+      poptval = ⁡
+      optval_size = (socklen_t) sizeof (af);
 #else  /* SO_PROTOCOL_INFOW */
-    WSAPROTOCOL_INFOW prot_info;
-    opt_name = SO_PROTOCOL_INFOW;
-    poptval = &prot_info;
-    optval_size = (socklen_t) sizeof (prot_info);
+      WSAPROTOCOL_INFOW prot_info;
+      opt_name = SO_PROTOCOL_INFOW;
+      poptval = &prot_info;
+      optval_size = (socklen_t) sizeof (prot_info);
 #endif /* SO_PROTOCOL_INFOW */
 
-    if (0 == getsockopt (daemon->listen_fd,
-                         SOL_SOCKET,
-                         opt_name,
-                         poptval,
-                         &optval_size))
-    {
+      if (0 == getsockopt (daemon->listen_fd,
+                           SOL_SOCKET,
+                           opt_name,
+                           poptval,
+                           &optval_size))
+      {
 #ifndef SO_DOMAIN
-      af = prot_info.iAddressFamily;
+        af = prot_info.iAddressFamily;
 #endif /* SO_DOMAIN */
-      switch (af)
-      {
-      case AF_INET:
-        daemon->listen_is_unix = _MHD_NO;
-        break;
+        switch (af)
+        {
+        case AF_INET:
+          daemon->listen_is_unix = _MHD_NO;
+          break;
 #ifdef HAVE_INET6
-      case AF_INET6:
-        *pflags |= MHD_USE_IPv6;
-        daemon->listen_is_unix = _MHD_NO;
-        break;
+        case AF_INET6:
+          *pflags |= MHD_USE_IPv6;
+          daemon->listen_is_unix = _MHD_NO;
+          break;
 #endif /* HAVE_INET6 */
 #ifdef AF_UNIX
-      case AF_UNIX:
-        daemon->port = 0;     /* special value for UNIX domain sockets */
-        daemon->listen_is_unix = _MHD_YES;
-        break;
+        case AF_UNIX:
+          daemon->port = 0;     /* special value for UNIX domain sockets */
+          daemon->listen_is_unix = _MHD_YES;
+          break;
 #endif /* AF_UNIX */
-      default:
-        daemon->port = 0;     /* ugh */
-        daemon->listen_is_unix = _MHD_UNKNOWN;
-        break;
+        default:
+          daemon->port = 0;     /* ugh */
+          daemon->listen_is_unix = _MHD_UNKNOWN;
+          break;
+        }
       }
-    }
-    else
+      else
 #endif /* SOL_SOCKET && (SO_DOMAIN || SO_PROTOCOL_INFOW)) */
-    daemon->listen_is_unix = _MHD_UNKNOWN;
+      daemon->listen_is_unix = _MHD_UNKNOWN;
+    }
 
     listen_fd = daemon->listen_fd;
 #ifdef MHD_USE_GETSOCKNAME
@@ -8492,6 +8510,7 @@ MHD_start_daemon_va (unsigned int flags,
          * to handle a new connection, but only one will win the race.
          * The others must immediately return. */
         MHD_socket_close_chk_ (listen_fd);
+        listen_fd = MHD_INVALID_SOCKET;
         goto free_and_fail;
       }
       daemon->listen_nonblk = false;
@@ -8820,6 +8839,7 @@ thread_failed:
   {
     if (MHD_INVALID_SOCKET != listen_fd)
       MHD_socket_close_chk_ (listen_fd);
+    listen_fd = MHD_INVALID_SOCKET;
     MHD_mutex_destroy_chk_ (&daemon->per_ip_connection_mutex);
     if (NULL != daemon->worker_pool)
       free (daemon->worker_pool);
@@ -8876,6 +8896,11 @@ free_and_fail:
 #endif /* HTTPS_SUPPORT */
   if (MHD_ITC_IS_VALID_ (daemon->itc))
     MHD_itc_destroy_chk_ (daemon->itc);
+  if (MHD_INVALID_SOCKET != listen_fd)
+    (void) MHD_socket_close_ (listen_fd);
+  if ((MHD_INVALID_SOCKET != daemon->listen_fd) &&
+      (listen_fd != daemon->listen_fd))
+    (void) MHD_socket_close_ (daemon->listen_fd);
   free (daemon);
   return NULL;
 }

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]