]> git.sesse.net Git - vlc/commitdiff
Fix Windows case which implements fd_set differently:
authorRémi Denis-Courmont <rem@videolan.org>
Fri, 18 Jan 2008 17:36:34 +0000 (17:36 +0000)
committerRémi Denis-Courmont <rem@videolan.org>
Fri, 18 Jan 2008 17:36:34 +0000 (17:36 +0000)
POSIX does not define FD_SET for fd >= FD_SETSIZE (=> buffer overflow).
Windows makes FD_SET a no-op if there are already FD_SETSIZE descriptors in the set.

modules/misc/lua/net.c

index c26f82744a0fe9a600113b2f015d8c45b13b6fab..d982cc1807b5e79b1676518f8f1b40a4f1034494 100644 (file)
@@ -136,8 +136,10 @@ int vlclua_net_select( lua_State *L )
     double f_timeout = luaL_checknumber( L, 4 );
     struct timeval timeout;
 
+#ifndef WIN32
     if( i_nfds > FD_SETSIZE )
         i_nfds = FD_SETSIZE;
+#endif
     timeout.tv_sec = (int)f_timeout;
     timeout.tv_usec = (int)(1e6*(f_timeout-(double)((int)f_timeout)));
     i_ret = select( i_nfds, fds_read, fds_write, 0, &timeout );
@@ -172,7 +174,8 @@ int vlclua_fd_set( lua_State *L )
     fd_set *fds = (fd_set*)luaL_checkuserdata( L, 1, sizeof( fd_set ) );
     int i_fd = luaL_checkint( L, 2 );
     /* FIXME: we should really use poll() instead here, but that breaks the
-     * VLC/LUA API*/
+     * VLC/LUA API. On Windows, overflow protection is built-in FD_SET, not
+     * on POSIX. In both cases, run-time behavior will however be wrong. */
 #ifndef WIN32
     if( i_fd < FD_SETSIZE )
 #endif