Don't allow the fd count to exceed FD_SETSIZE.

This commit is contained in:
Adrian Chadd 2016-03-31 16:17:42 -07:00
parent 18db423b1d
commit 84f4376c6c

View File

@ -49,6 +49,10 @@
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/time.h> #include <sys/time.h>
#ifdef HAVE_SYS_SELECT_H #ifdef HAVE_SYS_SELECT_H
// You may need to override this!
// #define FD_SETSIZE 2048
#include <sys/select.h> #include <sys/select.h>
#endif #endif
#ifdef HAVE_KEVENT #ifdef HAVE_KEVENT
@ -1076,6 +1080,15 @@ core_connect(Conn * s)
goto failure; goto failure;
} }
if (sd > FD_SETSIZE) {
fprintf(stderr,
"%s.core_connect.socket: sd > FD_SETSIZE (%d)\n",
prog_name,
FD_SETSIZE);
close(sd);
goto failure;
}
if (fcntl(sd, F_SETFL, O_NONBLOCK) < 0) { if (fcntl(sd, F_SETFL, O_NONBLOCK) < 0) {
fprintf(stderr, "%s.core_connect.fcntl: %s\n", fprintf(stderr, "%s.core_connect.fcntl: %s\n",
prog_name, strerror(errno)); prog_name, strerror(errno));