Subject: Re: sys_select() EBADF bug
To: <>
From: Tad Hunt <tad@entrisphere.com>
List: tech-kern
Date: 11/14/2002 18:00:40
sys_select()
{
...
/*
* A process cannot select on more fd's than it has open.
*/
if (SCARG(uap, nd) > p->p_fd->fd_nfiles)
return (EINVAL);
...
}
I think this is better than silently truncating "nd" to the number
of open files. Since the kernel doesn't know what FD_SETSIZE
is for the user process, the best it can do is return EBADF for
bad fd's which are less than fd_nfiles. Since you don't want to
trust the user process to give you a valid "nd", I think it is
best to return an error if "nd" is too big, than to silently
allow select to block when there might be fd's in the list which are
bad.
That is, EINVAL is better than nothing, but EBADF would be best.
I'm not sure how Solaris knows if the nfds argument is >= FD_SETSIZE,
since the fd_set structure doesn't have a member containing the size
the user set, but their manpage is clear that nfds is restricted to
FD_SETSIZE:
...
EINVAL
The nfds argument is less than 0, or greater than or
equal to FD_SETSIZE.
- Solaris 5.8 select(3c) manpage
-Tad