From owner-freebsd-standards@FreeBSD.ORG Mon Jul 2 20:28:45 2012 Return-Path: Delivered-To: freebsd-standards@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id BC3431065673 for ; Mon, 2 Jul 2012 20:28:45 +0000 (UTC) (envelope-from bjk@freebsd.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id A6E3C8FC14 for ; Mon, 2 Jul 2012 20:28:45 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.5/8.14.5) with ESMTP id q62KSjZQ096430 for ; Mon, 2 Jul 2012 20:28:45 GMT (envelope-from bjk@freebsd.org) Received: from localhost (bjk@localhost) by freefall.freebsd.org (8.14.5/8.14.5/Submit) with ESMTP id q62KSj36096427 for ; Mon, 2 Jul 2012 20:28:45 GMT (envelope-from bjk@freebsd.org) X-Authentication-Warning: freefall.freebsd.org: bjk owned process doing -bs Date: Mon, 2 Jul 2012 20:28:45 +0000 (UTC) From: Benjamin Kaduk To: freebsd-standards@freebsd.org Message-ID: User-Agent: Alpine 2.00 (BSF 1167 2008-08-23) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; format=flowed; charset=US-ASCII Subject: FD_SETSIZE: signed or unsigned? X-BeenThere: freebsd-standards@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Standards compliance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 02 Jul 2012 20:28:45 -0000 Hi all, We've had an unsigned FD_SETSIZE since 2002 (r90135, by markm): %%%%%%%%%%%%%%%%%%%%%%%% Revision 90135 - (show annotations) Sun Feb 3 11:36:59 2002 UTC (10 years, 5 months ago) by markm File MIME type: text/plain File size: 7279 byte(s) Zero functional difference; make some integer constants unsigned, as they are used in unsigned context. This shuts lint(1) up in a few significant ways with "signed/unsigned" arithmetic warnings. %%%%%%%%%%%%%%%%%%%%%%%% Yet NetBSD, Linux, and OpenBSD all have signed (plain int) FD_SETSIZEs. This has led to various pieces of software introducing casts and workarounds for the FreeBSD behavior, which (apparently) was itself made in order to attempt to reduce the occurence of warnings. Before I go and introduce such workarounds into our codebase for $work, I wanted to check with the standards gurus to see whether there is any chance that FreeBSD is what needs fixing, first. Bruce touched on some related issues on freebsd-security a few months later in 2002 ("[provos@citi.umich.edu: OpenBSD Security Advisory: Select Boundary Condition]"), but I can't really derive anything decisive from it. In any case, it is clear that a negative value for FD_SETSIZE is nonsensical. Doing a quick survey, it seems to mostly be used as the first argument to select(2) (which is an int type argument), and as a bound check on fd numbers (before using them in select). Given the former, it seems dubious to consider ever using a value between INT_MAX and UINT_MAX, which does leave open what the actual type should be. POSIX is delightfully vague: %%%%%%%%%%%%%%%%%%%%%% The following shall be defined as a macro: FD_SETSIZE Maximum number of file descriptors in an fd_set structure. %%%%%%%%%%%%%%%%%%%%%% Further thoughts on the matter are welcome. -Ben