From: Fabian Keil Date: Fri, 1 Mar 2013 17:38:34 +0000 (+0000) Subject: Reject network sockets with file descriptor values >= FD_SETSIZE X-Git-Tag: v_3_0_21~43 X-Git-Url: http://www.privoxy.org/gitweb/?p=privoxy.git;a=commitdiff_plain;h=b081249a57fcdcd2990db66e384d5a15dc2dc4cf Reject network sockets with file descriptor values >= FD_SETSIZE .. on platforms where they can't be select()ed. The assumption that they are only usable for mingw32 builds on Windows might be wrong. --- diff --git a/jbsockets.c b/jbsockets.c index d650dba1..5bdfcb18 100644 --- a/jbsockets.c +++ b/jbsockets.c @@ -1,4 +1,4 @@ -const char jbsockets_rcs[] = "$Id: jbsockets.c,v 1.119 2012/10/23 10:17:36 fabiankeil Exp $"; +const char jbsockets_rcs[] = "$Id: jbsockets.c,v 1.120 2013/01/01 22:11:08 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/jbsockets.c,v $ @@ -278,6 +278,17 @@ static jb_socket rfc2553_connect_to(const char *host, int portnum, struct client continue; } +#ifndef _WIN32 + if (fd >= FD_SETSIZE) + { + log_error(LOG_LEVEL_ERROR, + "Server socket number too high to use select(): %d >= %d", + fd, FD_SETSIZE); + close_socket(fd); + return JB_INVALID_SOCKET; + } +#endif + #ifdef TCP_NODELAY { /* turn off TCP coalescence */ int mi = 1; @@ -460,6 +471,17 @@ static jb_socket no_rfc2553_connect_to(const char *host, int portnum, struct cli return(JB_INVALID_SOCKET); } +#ifndef _WIN32 + if (fd >= FD_SETSIZE) + { + log_error(LOG_LEVEL_ERROR, + "Server socket number too high to use select(): %d >= %d", + fd, FD_SETSIZE); + close_socket(fd); + return JB_INVALID_SOCKET; + } +#endif + #ifdef TCP_NODELAY { /* turn off TCP coalescence */ int mi = 1; @@ -1286,6 +1308,17 @@ int accept_connection(struct client_state * csp, jb_socket fds[]) } #endif +#ifndef _WIN32 + if (afd >= FD_SETSIZE) + { + log_error(LOG_LEVEL_ERROR, + "Client socket number too high to use select(): %d >= %d", + afd, FD_SETSIZE); + close_socket(afd); + return 0; + } +#endif + csp->cfd = afd; #ifdef HAVE_RFC2553 csp->ip_addr_str = malloc(NI_MAXHOST); diff --git a/jcc.c b/jcc.c index 53de19a6..8d3c79e4 100644 --- a/jcc.c +++ b/jcc.c @@ -1,4 +1,4 @@ -const char jcc_rcs[] = "$Id: jcc.c,v 1.421 2012/12/07 12:50:37 fabiankeil Exp $"; +const char jcc_rcs[] = "$Id: jcc.c,v 1.423 2013/01/03 15:25:08 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/jcc.c,v $ @@ -3682,6 +3682,15 @@ static jb_socket bind_port_helper(const char *haddr, int hport) return JB_INVALID_SOCKET; } +#ifndef _WIN32 + if (bfd >= FD_SETSIZE) + { + log_error(LOG_LEVEL_FATAL, + "Bind socket number too high to use select(): %d >= %d", + bfd, FD_SETSIZE); + } +#endif + if (haddr == NULL) { log_error(LOG_LEVEL_INFO, "Listening on port %d on all IP addresses",