STINNER Victor <[email protected]> added the comment:
You don't check that 0 <= fd (e.g. oss.close()).
The select has a specific code for Visual Studio (don't check v < FD_SETSIZE):
#if defined(_MSC_VER)
max = 0; /* not used for Win32 */
#else /* !_MSC_VER */
if (v < 0 || v >= FD_SETSIZE) {
PyErr_SetString(PyExc_ValueError,
"filedescriptor out of range in select()");
goto finally;
}
if (v > max)
max = v;
#endif /* _MSC_VER */
Python has a _PyVerify_fd() function. We might write a similar function/macro
to check if a file descriptor can be used in a file descriptor set. FD_SET() is
used in the oss, readline, socket and _ssl modules. The socket module has a
IS_SELECTABLE() macro:
#ifdef Py_SOCKET_FD_CAN_BE_GE_FD_SETSIZE
/* Platform can select file descriptors beyond FD_SETSIZE */
#define IS_SELECTABLE(s) 1
#elif defined(HAVE_POLL)
/* Instead of select(), we'll use poll() since poll() works on any fd. */
#define IS_SELECTABLE(s) 1
/* Can we call select() with this socket without a buffer overrun? */
#else
/* POSIX says selecting file descriptors beyond FD_SETSIZE
has undefined behaviour. If there's no timeout left, we don't have to
call select, so it's a safe, little white lie. */
#define IS_SELECTABLE(s) ((s)->sock_fd < FD_SETSIZE || s->sock_timeout <= 0.0)
#endif
Note: do you really use the OSS module? On which OS? :)
----------
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue12287>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com