X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;ds=inline;f=lib%2Fselect.c;h=3a01b4a27335f46dda5abdfc93dbaa7d8b12cac5;hb=2b7c2713dc823b924ec88f481be1671bf53b6da3;hp=e7ca97cd54483089b5a2b7639c7d7bddf94d9f3f;hpb=4bacd42cee65eb44bd3aabfb01ac682fa9c7a3ce;p=gnulib.git diff --git a/lib/select.c b/lib/select.c index e7ca97cd5..3a01b4a27 100644 --- a/lib/select.c +++ b/lib/select.c @@ -1,7 +1,7 @@ /* Emulation for select(2) Contributed by Paolo Bonzini. - Copyright 2008-2012 Free Software Foundation, Inc. + Copyright 2008-2013 Free Software Foundation, Inc. This file is part of gnulib. @@ -506,6 +506,9 @@ restart: #else /* ! Native Windows. */ #include +#include /* NULL */ +#include +#include #undef select @@ -513,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) {