2006-11-09 Dick Porter <dick@ximian.com>
authorDick Porter <dick@acm.org>
Thu, 9 Nov 2006 16:50:14 +0000 (16:50 -0000)
committerDick Porter <dick@acm.org>
Thu, 9 Nov 2006 16:50:14 +0000 (16:50 -0000)
        * sockets.c (_wapi_select): Do some sanity checking on the
        fd_sets, to avoid file descriptors > FD_SETSIZE.
        (_wapi_FD_CLR, _wapi_FD_ISSET, _wapi_FD_SET): Avoid file
        descriptors > FD_SETSIZE.

svn path=/trunk/mono/; revision=67609

mono/io-layer/ChangeLog
mono/io-layer/sockets.c

index 3dd5ec1513d432c6319542d6bbe459ecf73320c3..bfd1a4bb9e21d67c1ef226ef7e3f7660bd80fe9b 100644 (file)
@@ -1,3 +1,10 @@
+2006-11-09  Dick Porter  <dick@ximian.com>
+
+       * sockets.c (_wapi_select): Do some sanity checking on the
+       fd_sets, to avoid file descriptors > FD_SETSIZE.
+       (_wapi_FD_CLR, _wapi_FD_ISSET, _wapi_FD_SET): Avoid file
+       descriptors > FD_SETSIZE.
+
 2006-10-27  Dick Porter  <dick@ximian.com>
 
        * io.c (GetFileAttributes): Force symlinks to directories to be
index 5659c69762297e1ea261ed68f33525101cf5f8e6..cd0f7449a1a2082ff95286aed5022af178bc39eb 100644 (file)
@@ -871,15 +871,28 @@ int ioctlsocket(guint32 fd, gint32 command, gpointer arg)
 int _wapi_select(int nfds G_GNUC_UNUSED, fd_set *readfds, fd_set *writefds,
                 fd_set *exceptfds, struct timeval *timeout)
 {
-       int ret;
+       int ret, maxfd;
        
        if (startup_count == 0) {
                WSASetLastError (WSANOTINITIALISED);
                return(SOCKET_ERROR);
        }
 
+       for (maxfd = FD_SETSIZE-1; maxfd >= 0; maxfd--) {
+               if ((readfds && FD_ISSET (maxfd, readfds)) ||
+                   (writefds && FD_ISSET (maxfd, writefds)) ||
+                   (exceptfds && FD_ISSET (maxfd, exceptfds))) {
+                       break;
+               }
+       }
+
+       if (maxfd == -1) {
+               WSASetLastError (WSAEINVAL);
+               return(SOCKET_ERROR);
+       }
+
        do {
-               ret = select(getdtablesize (), readfds, writefds, exceptfds,
+               ret = select(maxfd + 1, readfds, writefds, exceptfds,
                             timeout);
        } while (ret == -1 && errno == EINTR &&
                 !_wapi_thread_cur_apc_pending ());
@@ -902,6 +915,11 @@ void _wapi_FD_CLR(guint32 fd, fd_set *set)
 {
        gpointer handle = GUINT_TO_POINTER (fd);
        
+       if (fd >= FD_SETSIZE) {
+               WSASetLastError (WSAEINVAL);
+               return;
+       }
+       
        if (_wapi_handle_type (handle) != WAPI_HANDLE_SOCKET) {
                WSASetLastError (WSAENOTSOCK);
                return;
@@ -914,6 +932,11 @@ int _wapi_FD_ISSET(guint32 fd, fd_set *set)
 {
        gpointer handle = GUINT_TO_POINTER (fd);
        
+       if (fd >= FD_SETSIZE) {
+               WSASetLastError (WSAEINVAL);
+               return(0);
+       }
+       
        if (_wapi_handle_type (handle) != WAPI_HANDLE_SOCKET) {
                WSASetLastError (WSAENOTSOCK);
                return(0);
@@ -926,6 +949,11 @@ void _wapi_FD_SET(guint32 fd, fd_set *set)
 {
        gpointer handle = GUINT_TO_POINTER (fd);
        
+       if (fd >= FD_SETSIZE) {
+               WSASetLastError (WSAEINVAL);
+               return;
+       }
+
        if (_wapi_handle_type (handle) != WAPI_HANDLE_SOCKET) {
                WSASetLastError (WSAENOTSOCK);
                return;