Opened 3 weeks ago

Closed 3 weeks ago

#19220 closed bug (fixed)

select() does not support a first argument up to FD_SETSIZE

Reported by: bhaible Owned by: nobody
Priority: normal Milestone: R1/beta6
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)

foo.c (301 bytes ) - added by bhaible 3 weeks ago.
test case foo.c

Download all attachments as: .zip

Change History (5)

by bhaible, 3 weeks ago

Attachment: foo.c added

test case foo.c

comment:1 by waddlesplash, 3 weeks ago

The kernel returns EINVAL here because it knows the process doesn't have at least 513 opened FDs.

comment:2 by bhaible, 3 weeks 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 bhaible, 3 weeks 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

comment:4 by waddlesplash, 3 weeks ago

Milestone: UnscheduledR1/beta6
Resolution: fixed
Status: newclosed

Fixed in hrev58293.

Note: See TracTickets for help on using tickets.