gnunet-svn
[Top][All Lists]
Advanced

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

[libmicrohttpd] branch master updated (e62cd69d -> a5649931)


From: gnunet
Subject: [libmicrohttpd] branch master updated (e62cd69d -> a5649931)
Date: Fri, 10 Nov 2023 15:40:09 +0100

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

karlson2k pushed a change to branch master
in repository libmicrohttpd.

    from e62cd69d Fixed copy-paste error introduced by 
2475030dcbdb95f6843d251d6e4ee1b4be9f3f3b
     new cfc79048 .gitlab-ci.yml: removed "keep-going" make flag
     new aec99382 daemon.c: moved processing and checking of app-provided 
listen socket
     new e47f63a3 MHD_start_daemon(): mark listen as UNIX based on available 
information
     new 068f4b6b MHD_start_daemon(): added some asserts
     new 696e0401 MHD_D_DOES_SCKT_FIT_FDSET_(): simplified macro
     new c211e198 MHD_start_daemon(): added stricter checks for bind() and 
listen() return values
     new a5649931 MHD_start_daemon(): added check for epoll FD to fit fd_set 
for external polling mode

The 7 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:
 .gitlab-ci.yml            |   4 +-
 src/microhttpd/daemon.c   | 146 +++++++++++++++++++++++++++++++---------------
 src/microhttpd/internal.h |   4 +-
 src/microhttpd/response.c |   4 +-
 4 files changed, 104 insertions(+), 54 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index f1023d59..af754881 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -38,7 +38,7 @@ gcc/Stretch:
     - export CFLAGS="$CFLAGS_DEFAULT"
     - ./bootstrap
     - ./configure $CONFIGURE_BASE_FLAGS --enable-build-type=debug 
--disable-sanitizers
-    - make -j$(nproc) && make -k check
+    - make -j$(nproc) && make check
   tags:
     - shared
     - linux
@@ -62,7 +62,7 @@ Sanitizers/Stretch:
     - export CC="ccache clang"
     - export ASAN_SYMBOLIZER_PATH=/usr/lib/llvm-3.8/bin/llvm-symbolizer
     - ./configure $CONFIGURE_BASE_FLAGS --disable-doc 
--enable-build-type=debug --enable-sanitizers
-    - make -j$(nproc) && make -k check
+    - make -j$(nproc) && make check
   tags:
     - shared
     - linux
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index a53ba0d5..283e0839 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -1,7 +1,7 @@
 /*
   This file is part of libmicrohttpd
   Copyright (C) 2007-2018 Daniel Pittman and Christian Grothoff
-  Copyright (C) 2015-2021 Evgeny Grin (Karlson2k)
+  Copyright (C) 2015-2023 Evgeny Grin (Karlson2k)
 
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
@@ -3060,7 +3060,7 @@ internal_add_connection (struct MHD_Daemon *daemon,
 #endif
 
   if (MHD_D_IS_USING_SELECT_ (daemon) &&
-      (! MHD_D_DOES_SCKT_FIT_FDSET_ (client_socket, NULL, daemon)) )
+      (! MHD_D_DOES_SCKT_FIT_FDSET_ (client_socket, daemon)) )
   {
 #ifdef HAVE_MESSAGES
     MHD_DLOG (daemon,
@@ -6173,6 +6173,15 @@ struct MHD_InterimParams_
    * The value for #MHD_OPTION_APP_FD_SETSIZE set by application.
    */
   int fdset_size;
+  /**
+   * Set to 'true' if @a listen_fd is set by application.
+   */
+  bool listen_fd_set;
+  /**
+   * Application-provided listen socket.
+   */
+  MHD_socket listen_fd;
+
 };
 
 /**
@@ -6904,39 +6913,9 @@ parse_options_va (struct MHD_Daemon *daemon,
       break;
 #endif
     case MHD_OPTION_LISTEN_SOCKET:
-      if (0 != (daemon->options & MHD_USE_NO_LISTEN_SOCKET))
-      {
-#ifdef HAVE_MESSAGES
-        MHD_DLOG (daemon,
-                  _ ("MHD_OPTION_LISTEN_SOCKET specified for daemon "
-                     "with MHD_USE_NO_LISTEN_SOCKET flag set.\n"));
-#endif
-        return MHD_NO;
-      }
-      else
-      {
-        daemon->listen_fd = va_arg (ap,
-                                    MHD_socket);
-#if defined(SO_DOMAIN) && defined(AF_UNIX)
-        {
-          int af;
-          socklen_t len = sizeof (af);
-
-          if (0 == getsockopt (daemon->listen_fd,
-                               SOL_SOCKET,
-                               SO_DOMAIN,
-                               &af,
-                               &len))
-          {
-            daemon->listen_is_unix = (AF_UNIX == af) ? _MHD_YES : _MHD_NO;
-          }
-          else
-            daemon->listen_is_unix = _MHD_UNKNOWN;
-        }
-#else  /* ! SO_DOMAIN || ! AF_UNIX */
-        daemon->listen_is_unix = _MHD_UNKNOWN;
-#endif /* ! SO_DOMAIN || ! AF_UNIX */
-      }
+      params->listen_fd = va_arg (ap,
+                                  MHD_socket);
+      params->listen_fd_set = true;
       break;
     case MHD_OPTION_EXTERNAL_LOGGER:
 #ifdef HAVE_MESSAGES
@@ -7288,6 +7267,25 @@ setup_epoll_to_listen (struct MHD_Daemon *daemon)
                (MHD_INVALID_SOCKET != (ls = daemon->listen_fd)) || \
                MHD_ITC_IS_VALID_ (daemon->itc) );
   daemon->epoll_fd = setup_epoll_fd (daemon);
+  if (! MHD_D_IS_USING_THREADS_ (daemon)
+      && (0 != (daemon->options & MHD_USE_AUTO)))
+  {
+    /* Application requested "MHD_USE_AUTO", probably MHD_get_fdset() will be
+       used.
+       Make sure that epoll FD is suitable for fd_set.
+       Actually, MHD_get_fdset() is allowed for MHD_USE_EPOLL direct,
+       but most probably direct requirement for MHD_USE_EPOLL means that
+       epoll FD will be used directly. This logic is fuzzy, but better
+       than nothing with current MHD API. */
+    if (! MHD_D_DOES_SCKT_FIT_FDSET_ (daemon->epoll_fd, daemon))
+    {
+#ifdef HAVE_MESSAGES
+      MHD_DLOG (daemon,
+                _ ("The epoll FD is too large to be used with fd_set.\n"));
+#endif /* HAVE_MESSAGES */
+      return MHD_NO;
+    }
+  }
   if (-1 == daemon->epoll_fd)
     return MHD_NO;
 #if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
@@ -7404,6 +7402,54 @@ process_interim_params (struct MHD_Daemon *d,
 #endif /* MHD_POSIX_SOCKETS */
     }
   }
+
+  if (params->listen_fd_set)
+  {
+    if (MHD_INVALID_SOCKET == params->listen_fd
+#ifdef MHD_POSIX_SOCKETS
+        || 0 > params->listen_fd
+#endif /* MHD_POSIX_SOCKETS */
+        )
+    {
+#ifdef HAVE_MESSAGES
+      MHD_DLOG (d,
+                _ ("The value provided for MHD_OPTION_LISTEN_SOCKET " \
+                   "is invalid.\n"));
+#endif /* HAVE_MESSAGES */
+      return false;
+    }
+    else if (0 != (d->options & MHD_USE_NO_LISTEN_SOCKET))
+    {
+#ifdef HAVE_MESSAGES
+      MHD_DLOG (d,
+                _ ("MHD_OPTION_LISTEN_SOCKET specified for daemon "
+                   "with MHD_USE_NO_LISTEN_SOCKET flag set.\n"));
+#endif /* HAVE_MESSAGES */
+      (void) MHD_socket_close_ (params->listen_fd);
+      return false;
+    }
+    else
+    {
+#if defined(SO_DOMAIN) && defined(AF_UNIX)
+      int af;
+      socklen_t len = sizeof (af);
+
+      if (0 == getsockopt (d->listen_fd,
+                           SOL_SOCKET,
+                           SO_DOMAIN,
+                           &af,
+                           &len))
+      {
+        d->listen_is_unix = (AF_UNIX == af) ? _MHD_YES : _MHD_NO;
+      }
+      else
+        d->listen_is_unix = _MHD_UNKNOWN;
+#else  /* ! SO_DOMAIN || ! AF_UNIX */
+      d->listen_is_unix = _MHD_UNKNOWN;
+#endif /* ! SO_DOMAIN || ! AF_UNIX */
+      d->listen_fd = params->listen_fd;
+    }
+  }
   return true;
 }
 
@@ -7615,6 +7661,8 @@ MHD_start_daemon_va (unsigned int flags,
 
   interim_params->fdset_size_set = false;
   interim_params->fdset_size = 0;
+  interim_params->listen_fd_set = false;
+  interim_params->listen_fd = MHD_INVALID_SOCKET;
 
   if (MHD_NO == parse_options_va (daemon,
                                   &servaddr,
@@ -7698,8 +7746,7 @@ MHD_start_daemon_va (unsigned int flags,
       return NULL;
     }
     if (MHD_D_IS_USING_SELECT_ (daemon) &&
-        (! MHD_D_DOES_SCKT_FIT_FDSET_ (MHD_itc_r_fd_ (daemon->itc), \
-                                       NULL, daemon)) )
+        (! MHD_D_DOES_SCKT_FIT_FDSET_ (MHD_itc_r_fd_ (daemon->itc), daemon)) )
     {
 #ifdef HAVE_MESSAGES
       MHD_DLOG (daemon,
@@ -7827,6 +7874,7 @@ MHD_start_daemon_va (unsigned int flags,
 #endif
       goto free_and_fail;
     }
+    daemon->listen_is_unix = _MHD_NO;
 
     /* Apply the socket options according to listening_address_reuse. */
     if (0 == daemon->listening_address_reuse)
@@ -8007,7 +8055,7 @@ MHD_start_daemon_va (unsigned int flags,
 #endif
 #endif
     }
-    if (-1 == bind (listen_fd, servaddr, addrlen))
+    if (0 != bind (listen_fd, servaddr, addrlen))
     {
 #ifdef HAVE_MESSAGES
       MHD_DLOG (daemon,
@@ -8037,8 +8085,8 @@ MHD_start_daemon_va (unsigned int flags,
       }
     }
 #endif
-    if (listen (listen_fd,
-                (int) daemon->listen_backlog_size) < 0)
+    if (0 != listen (listen_fd,
+                     (int) daemon->listen_backlog_size))
     {
 #ifdef HAVE_MESSAGES
       MHD_DLOG (daemon,
@@ -8093,6 +8141,8 @@ MHD_start_daemon_va (unsigned int flags,
       /* Many non-Linux-based platforms return zero addrlen
        * for AF_UNIX sockets */
       daemon->port = 0;     /* special value for UNIX domain sockets */
+      if (_MHD_UNKNOWN == daemon->listen_is_unix)
+        daemon->listen_is_unix = _MHD_YES;
     }
 #endif /* __linux__ */
 #endif /* MHD_POSIX_SOCKETS */
@@ -8120,14 +8170,16 @@ MHD_start_daemon_va (unsigned int flags,
 #ifdef AF_UNIX
       case AF_UNIX:
         daemon->port = 0;     /* special value for UNIX domain sockets */
+        daemon->listen_is_unix = _MHD_YES;
         break;
 #endif
       default:
 #ifdef HAVE_MESSAGES
         MHD_DLOG (daemon,
-                  _ ("Unknown address family!\n"));
+                  _ ("Listen socket has unknown address family!\n"));
 #endif
         daemon->port = 0;     /* ugh */
+        daemon->listen_is_unix = _MHD_UNKNOWN;
         break;
       }
     }
@@ -8136,6 +8188,7 @@ MHD_start_daemon_va (unsigned int flags,
 
   if (MHD_INVALID_SOCKET != listen_fd)
   {
+    mhd_assert (0 == (*pflags & MHD_USE_NO_LISTEN_SOCKET));
     if (! MHD_socket_nonblocking_ (listen_fd))
     {
 #ifdef HAVE_MESSAGES
@@ -8160,9 +8213,7 @@ MHD_start_daemon_va (unsigned int flags,
     else
       daemon->listen_nonblk = true;
     if (MHD_D_IS_USING_SELECT_ (daemon) &&
-        (! MHD_D_DOES_SCKT_FIT_FDSET_ (listen_fd, \
-                                       NULL, \
-                                       daemon)) )
+        (! MHD_D_DOES_SCKT_FIT_FDSET_ (listen_fd, daemon)) )
     {
 #ifdef HAVE_MESSAGES
       MHD_DLOG (daemon,
@@ -8176,7 +8227,10 @@ MHD_start_daemon_va (unsigned int flags,
     }
   }
   else
+  {
+    mhd_assert (0 != (*pflags & MHD_USE_NO_LISTEN_SOCKET));
     daemon->listen_nonblk = false; /* Actually listen socket does not exist */
+  }
 
 #ifdef EPOLL_SUPPORT
   if (MHD_D_IS_USING_EPOLL_ (daemon)
@@ -8362,9 +8416,7 @@ MHD_start_daemon_va (unsigned int flags,
             goto thread_failed;
           }
           if (MHD_D_IS_USING_SELECT_ (d) &&
-              (! MHD_D_DOES_SCKT_FIT_FDSET_ (MHD_itc_r_fd_ (d->itc), \
-                                             NULL, \
-                                             daemon)) )
+              (! MHD_D_DOES_SCKT_FIT_FDSET_ (MHD_itc_r_fd_ (d->itc), daemon)) )
           {
 #ifdef HAVE_MESSAGES
             MHD_DLOG (daemon,
diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h
index eb87c8e6..3d7d774a 100644
--- a/src/microhttpd/internal.h
+++ b/src/microhttpd/internal.h
@@ -2586,8 +2586,8 @@ struct MHD_Daemon
 /**
  * Check whether socket @a sckt fits fd_sets used by the daemon @a d
  */
-#define MHD_D_DOES_SCKT_FIT_FDSET_(sckt,pset,d) \
-  MHD_SCKT_FD_FITS_FDSET_SETSIZE_(sckt,pset,MHD_D_GET_FD_SETSIZE_(d))
+#define MHD_D_DOES_SCKT_FIT_FDSET_(sckt,d) \
+  MHD_SCKT_FD_FITS_FDSET_SETSIZE_(sckt,NULL,MHD_D_GET_FD_SETSIZE_(d))
 
 
 #ifdef DAUTH_SUPPORT
diff --git a/src/microhttpd/response.c b/src/microhttpd/response.c
index 9e9c0d73..ab5e3750 100644
--- a/src/microhttpd/response.c
+++ b/src/microhttpd/response.c
@@ -2031,9 +2031,7 @@ MHD_response_execute_upgrade_ (struct MHD_Response 
*response,
     }
 #endif /* MHD_socket_nosignal_ */
     if (MHD_D_IS_USING_SELECT_ (daemon) &&
-        (! MHD_D_DOES_SCKT_FIT_FDSET_ (sv[1], \
-                                       NULL, \
-                                       daemon)) )
+        (! MHD_D_DOES_SCKT_FIT_FDSET_ (sv[1], daemon)) )
     {
 #ifdef HAVE_MESSAGES
       MHD_DLOG (daemon,

-- 
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]