Commit f49cbfc0 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Fix Windows case which implements fd_set differently:

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.
parent 60d35d6c
...@@ -136,8 +136,10 @@ int vlclua_net_select( lua_State *L ) ...@@ -136,8 +136,10 @@ int vlclua_net_select( lua_State *L )
double f_timeout = luaL_checknumber( L, 4 ); double f_timeout = luaL_checknumber( L, 4 );
struct timeval timeout; struct timeval timeout;
#ifndef WIN32
if( i_nfds > FD_SETSIZE ) if( i_nfds > FD_SETSIZE )
i_nfds = FD_SETSIZE; i_nfds = FD_SETSIZE;
#endif
timeout.tv_sec = (int)f_timeout; timeout.tv_sec = (int)f_timeout;
timeout.tv_usec = (int)(1e6*(f_timeout-(double)((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 ); i_ret = select( i_nfds, fds_read, fds_write, 0, &timeout );
...@@ -172,7 +174,8 @@ int vlclua_fd_set( lua_State *L ) ...@@ -172,7 +174,8 @@ int vlclua_fd_set( lua_State *L )
fd_set *fds = (fd_set*)luaL_checkuserdata( L, 1, sizeof( fd_set ) ); fd_set *fds = (fd_set*)luaL_checkuserdata( L, 1, sizeof( fd_set ) );
int i_fd = luaL_checkint( L, 2 ); int i_fd = luaL_checkint( L, 2 );
/* FIXME: we should really use poll() instead here, but that breaks the /* 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 #ifndef WIN32
if( i_fd < FD_SETSIZE ) if( i_fd < FD_SETSIZE )
#endif #endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment