Subject: lib/17746: FD_ZERO, sysconf(_SC_OPEN_MAX) and select() don't work together
To: None <>
From: None <>
List: netbsd-bugs
Date: 07/28/2002 13:46:27
>Number:         17746
>Category:       lib
>Synopsis:       FD_ZERO, sysconf(_SC_OPEN_MAX) and select() don't work together
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Jul 28 13:47:00 PDT 2002
>Originator:     Christian Biere
>Release:        NetBSD 1.6D
System: NetBSD localhost 1.6D NetBSD 1.6D (DURON2) #0: Sat Jul 27 08:52:59 CEST
2002 root@localhost:/usr/src/sys/arch/i386/compile/DURON2 i386
Architecture: i386
Machine: i386

Look at these code from /usr/include/sys/types.h:

#ifndef FD_SETSIZE
#define FD_SETSIZE      256

typedef struct fd_set {
        __fd_mask       fds_bits[__howmany(FD_SETSIZE, __NFDBITS)];
} fd_set;

#define FD_ZERO(p)      (void)memset((p), 0, sizeof(*(p)))

This means an application must not use the result of 
sysconf(_SC_OPEN_MAX) and use this as the first parameter for
select() if this value is higher than FD_SETSIZE. As the admin
may always increase this limit (kern.maxfiles, 
proc.curproc.rlimit.descriptors.hard) FD_SETSIZE and _SC_OPEN_MAX
can never be in sync.

Look at e.g. pkgsrc/x11/aterm and what it does with select() in
I don't know whether this can be fixed at all but it should be