Opened 4 hours ago
Last modified 3 hours ago
#19220 new bug
select() does not support a first argument up to FD_SETSIZE
Reported by: | bhaible | Owned by: | nobody |
---|---|---|---|
Priority: | normal | Milestone: | Unscheduled |
Component: | System/POSIX | Version: | R1/beta5 |
Keywords: | Cc: | ||
Blocked By: | Blocking: | ||
Platform: | All |
Description
The function select(), specified in https://pubs.opengroup.org/onlinepubs/9799919799/functions/select.html , should support a first argument up to FD_SETSIZE. This is clear
- from the definition of FD_SETSIZE as the number of bits in an fd_set,
- because if "The nfds argument is less than 0 or greater than FD_SETSIZE." an error EINVAL must be produced.
In Haiku (as of 2024-07-15), a first argument > FD_SETSIZE/2, <= FD_SETSIZE produces an error EINVAL. It shouldn't.
How to reproduce:
$ gcc foo.c $ ./a.out FD_SETSIZE = 1024 select: Invalid Argument
Attachments (1)
Change History (4)
by , 4 hours ago
comment:1 by , 3 hours ago
The kernel returns EINVAL here because it knows the process doesn't have at least 513 opened FDs.
comment:2 by , 3 hours ago
The kernel returns EINVAL here because it knows the process doesn't have at least 513 opened FDs.
This is not a valid reason to fail with EINVAL:
- Quote: "The nfds argument specifies the range of descriptors to be tested. The first nfds descriptors shall be checked in each set; that is, the descriptors from zero through nfds-1 in the descriptor sets shall be examined." Since all three fd_set arguments are NULL, none of the file descriptors in the range 0..nfds-1 needs to be examined.
- If one of the file descriptor sets would contain an FD that is invalid or not open, the correct error code for that case would be EBADF.
comment:3 by , 3 hours ago
Many packages call select() with a first argument of FD_SETSIZE: algol68g, GNU bash, bogl, GNU clisp, flrig, GNU gcc, GNU gdb, GNU gnupg, graphviz, imview, librep, GNU octave, pmacct, GNU poke, GNU readline, simgear, singular, sympathy, GNU texinfo, etc.
See https://codesearch.debian.net/search?q=select+%28FD_SETSIZE%2C&literal=1&perpkg=1
test case foo.c