NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

lib/57809: FD_ZERO is type-unsafe



>Number:         57809
>Category:       lib
>Synopsis:       FD_ZERO is type-unsafe
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Jan 01 22:05:00 +0000 2024
>Originator:     Taylor R Campbell
>Release:        current
>Organization:
The SetFD Foundation
>Environment:
>Description:
FD_ZERO in sys/select.h accepts arguments of any pointer type, not just fd_set *.

The other FD_* functions (FD_SET, FD_CLR, FD_ISSET) are also moderately type-unsafe, in that they accept a pointer to any struct or union that has a member called `fds_bits' of an appropriate type.
>How-To-Repeat:
$ cat pr.c
#include <sys/select.h>

fd_set readfds;

void
setup(int readfd)
{
	FD_ZERO(&readfd);
	FD_SET(readfd, &readfds);
}
$ make pr.o DBG=-g\ -O2\ -Wall\ -Wextra\ -Werror
cc -g -O2 -Wall -Wextra -Werror   -c pr.c
$ 

This should report a type error, but it does not.  Instead, because of the typo, it silently overwrites the local variable `readfd' and, for any input other than 0, puts the wrong fie descriptor into the fd set `readfds'.
>Fix:
Yes, please!

Maybe these should just be redefined as inline functions instead of as macros.



Home | Main Index | Thread Index | Old Index