From owner-freebsd-bugs@FreeBSD.ORG Sat Jul 17 12:10:11 2010 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 11547106567D for ; Sat, 17 Jul 2010 12:10:10 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 009B98FC08 for ; Sat, 17 Jul 2010 12:10:10 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.4/8.14.4) with ESMTP id o6HCA92l042817 for ; Sat, 17 Jul 2010 12:10:09 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.4/8.14.4/Submit) id o6HCA9xd042816; Sat, 17 Jul 2010 12:10:09 GMT (envelope-from gnats) Date: Sat, 17 Jul 2010 12:10:09 GMT Message-Id: <201007171210.o6HCA9xd042816@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org From: Jilles Tjoelker Cc: Subject: Re: kern/148581: [libc] fopen(3) fails with EMFILE if there are more than SHORT_MAX fds open X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Jilles Tjoelker List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 17 Jul 2010 12:10:11 -0000 The following reply was made to PR kern/148581; it has been noted by GNATS. From: Jilles Tjoelker To: bug-followup@FreeBSD.org, manishv@lineratesystems.com Cc: Subject: Re: kern/148581: [libc] fopen(3) fails with EMFILE if there are more than SHORT_MAX fds open Date: Sat, 17 Jul 2010 14:06:00 +0200 Strictly speaking, your very dirty supposedly safe fix breaks binary compatibility because fileno() (in non-threaded programs only) and fileno_unlocked() are macros that hard-code the location and size of the _file field into binaries. If you have code compiled before the change in the same process as code compiled after the change, it might happen that data is read/written from/to the wrong descriptor. What may work is extending FILE (although I'm not entirely sure that there is noone that allocates their own FILE) with a 32-bit file descriptor field. If the file descriptor exceeds 32767, the 16-bit field then contains -1 and fileno() in old binaries will return that. This will at least fail safely although fileno() is not defined to return error conditions (but it has always returned -1 if the FILE is not associated with a file descriptor). -- Jilles Tjoelker