libmicrohttpd

HTTP/1.x server C library (MHD 1.x, stable)
Log | Files | Refs | Submodules | README | LICENSE

commit b99f8207ec74607cb3f38c7f04295e5504d60bea
parent f0ca101e2295187e56729a00315ad18d3819c9da
Author: Christian Grothoff <christian@grothoff.org>
Date:   Thu,  8 Oct 2009 08:43:52 +0000

limit sockets to  < FD_SETSIZE

Diffstat:
MChangeLog | 5++++-
Msrc/daemon/daemon.c | 29+++++++++++++++++++++++++++--
2 files changed, 31 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog @@ -1,3 +1,6 @@ +Thu Oct 8 10:43:02 CEST 2009 + Added check for sockets being '< FD_SETSIZE' (just to be safe). -CG + Mon Oct 5 21:17:26 CEST 2009 Adding "COOKIE" header string #defines. -CG @@ -36,7 +39,7 @@ Thu May 14 21:20:30 MDT 2009 the next request was successfully transmitted). This could confuse applications not expecting to see a connection "complete" that they were never aware of in the first place. -CG - + Mon May 11 13:01:16 MDT 2009 Fixed issue where error code on timeout was "TERMINATED_WITH_ERROR" instead of "TERMINATED_TIMEOUT_REACHED". -CG diff --git a/src/daemon/daemon.c b/src/daemon/daemon.c @@ -577,7 +577,6 @@ MHD_accept_connection (struct MHD_Daemon *daemon) memset (addr, 0, sizeof (addrstorage)); s = ACCEPT (daemon->socket_fd, addr, &addrlen); - if ((s < 0) || (addrlen <= 0)) { #if HAVE_MESSAGES @@ -593,6 +592,20 @@ MHD_accept_connection (struct MHD_Daemon *daemon) } return MHD_NO; } + if (s >= FD_SETSIZE) + { +#if HAVE_MESSAGES + if ((options & MHD_USE_DEBUG) != 0) + FPRINTF (stderr, + "Socket descriptor larger than FD_SETSIZE: %d > %d\n", + s, + FD_SETSIZE); +#endif + CLOSE (s); + return MHD_NO; + } + + #if HAVE_MESSAGES #if DEBUG_CONNECT MHD_DLOG (daemon, "Accepted connection on socket %d\n", s); @@ -1163,7 +1176,7 @@ MHD_start_daemon_va (unsigned int options, } #endif else - socket_fd = SOCKET (PF_INET, SOCK_STREAM, 0); + socket_fd = SOCKET (PF_INET, SOCK_STREAM, 0); if (socket_fd < 0) { #if HAVE_MESSAGES @@ -1173,6 +1186,18 @@ MHD_start_daemon_va (unsigned int options, free (retVal); return NULL; } + if (socket_fd >= FD_SETSIZE) + { +#if HAVE_MESSAGES + if ((options & MHD_USE_DEBUG) != 0) + FPRINTF (stderr, + "Socket descriptor larger than FD_SETSIZE: %d > %d\n", + socket_fd, + FD_SETSIZE); +#endif + CLOSE (socket_fd); + return NULL; + } if ((SETSOCKOPT (socket_fd, SOL_SOCKET, SO_REUSEADDR,