X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fselect.c;fp=lib%2Fselect.c;h=1ff6652c65e015be9c36b57ce560cebe3d9dc6a9;hb=9500a55f083bb8e55ee938e4532ae6baea702e6b;hp=4db09a353d8087bedd80e0de317b423a77a6102f;hpb=2f58d08d66740bfe7fe5c581027965da04afecd7;p=gnulib.git diff --git a/lib/select.c b/lib/select.c index 4db09a353..1ff6652c6 100644 --- a/lib/select.c +++ b/lib/select.c @@ -507,6 +507,8 @@ restart: #include #include /* NULL */ +#include +#include #undef select @@ -514,6 +516,23 @@ int rpl_select (int nfds, fd_set *rfds, fd_set *wfds, fd_set *xfds, struct timeval *timeout) { + int i; + + /* FreeBSD 8.2 has a bug: it does not always detect invalid fds. */ + if (nfds < 0 || nfds > FD_SETSIZE) + { + errno = EINVAL; + return -1; + } + for (i = 0; i < nfds; i++) + { + if (((rfds && FD_ISSET (i, rfds)) + || (wfds && FD_ISSET (i, wfds)) + || (xfds && FD_ISSET (i, xfds))) + && dup2 (i, i) != i) + return -1; + } + /* Interix 3.5 has a bug: it does not support nfds == 0. */ if (nfds == 0) {