From owner-cvs-src@FreeBSD.ORG Wed Feb 27 19:02:04 2008 Return-Path: Delivered-To: cvs-src@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B433F106566B; Wed, 27 Feb 2008 19:02:04 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id ADEA58FC13; Wed, 27 Feb 2008 19:02:04 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id m1RJ23SJ012247; Wed, 27 Feb 2008 19:02:03 GMT (envelope-from jhb@repoman.freebsd.org) Received: (from jhb@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id m1RJ23wd012246; Wed, 27 Feb 2008 19:02:03 GMT (envelope-from jhb) Message-Id: <200802271902.m1RJ23wd012246@repoman.freebsd.org> From: John Baldwin Date: Wed, 27 Feb 2008 19:02:03 +0000 (UTC) To: src-committers@FreeBSD.org, cvs-src@FreeBSD.org, cvs-all@FreeBSD.org X-FreeBSD-CVS-Branch: HEAD Cc: Subject: cvs commit: src/lib/libc/stdio fdopen.c fopen.c freopen.c X-BeenThere: cvs-src@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: CVS commit messages for the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 27 Feb 2008 19:02:04 -0000 jhb 2008-02-27 19:02:02 UTC FreeBSD src repository Modified files: lib/libc/stdio fdopen.c fopen.c freopen.c Log: File descriptors are an int, but our stdio FILE object uses a short to hold them. Thus, any fd whose value is greater than SHRT_MAX is handled incorrectly (the short value is sign-extended when converted to an int). An unpleasant side effect is that if fopen() opens a file and gets a backing fd that is greater than SHRT_MAX, fclose() will fail and the file descriptor will be leaked. Better handle this by fixing fopen(), fdopen(), and freopen() to fail attempts to use a fd greater than SHRT_MAX with EMFILE. At some point in the future we should look at expanding the file descriptor in FILE to an int, but that is a bit complicated due to ABI issues. MFC after: 1 week Discussed on: arch Reviewed by: wollman Revision Changes Path 1.9 +12 -0 src/lib/libc/stdio/fdopen.c 1.12 +13 -0 src/lib/libc/stdio/fopen.c 1.19 +14 -0 src/lib/libc/stdio/freopen.c