Bounds check the argument to FD_SET

Failing to check the FD_SET argument against FD_SETSIZE causes
undefined behaviour (segfaults, for example).
master
Sam Roberts 2012-02-21 13:13:46 -08:00
parent 27a3964ff7
commit 0716cb868e
1 changed files with 1 additions and 0 deletions

View File

@ -49,6 +49,7 @@ int socket_waitfd(p_socket ps, int sw, p_timeout tm) {
fd_set rfds, wfds, *rp, *wp;
struct timeval tv, *tp;
double t;
if (*ps >= FD_SETSIZE) return EINVAL;
if (timeout_iszero(tm)) return IO_TIMEOUT; /* optimize timeout == 0 case */
do {
/* must set bits within loop, because select may have modifed them */