From owner-cvs-all@FreeBSD.ORG Wed Feb 27 20:18:55 2008 Return-Path: Delivered-To: cvs-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id C722610656C2; Wed, 27 Feb 2008 20:18:55 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from speedfactory.net (mail.speedfactory.net [66.23.216.219]) by mx1.freebsd.org (Postfix) with ESMTP id 0528F8FC26; Wed, 27 Feb 2008 20:18:49 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from server.baldwin.cx (unverified [66.23.211.162]) by speedfactory.net (SurgeMail 3.8s) with ESMTP id 233611897-1834499 for multiple; Wed, 27 Feb 2008 15:16:48 -0500 Received: from localhost.corp.yahoo.com (john@localhost [127.0.0.1]) (authenticated bits=0) by server.baldwin.cx (8.14.2/8.14.2) with ESMTP id m1RKIjlL036063; Wed, 27 Feb 2008 15:18:45 -0500 (EST) (envelope-from jhb@freebsd.org) From: John Baldwin To: src-committers@freebsd.org Date: Wed, 27 Feb 2008 15:11:10 -0500 User-Agent: KMail/1.9.7 References: <200802271902.m1RJ23wd012246@repoman.freebsd.org> In-Reply-To: <200802271902.m1RJ23wd012246@repoman.freebsd.org> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-15" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200802271511.10787.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH authentication, not delayed by milter-greylist-2.0.2 (server.baldwin.cx [127.0.0.1]); Wed, 27 Feb 2008 15:18:45 -0500 (EST) X-Virus-Scanned: ClamAV 0.91.2/6012/Wed Feb 27 13:48:06 2008 on server.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-4.4 required=4.2 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.1.3 X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on server.baldwin.cx Cc: cvs-src@freebsd.org, cvs-all@freebsd.org Subject: Re: cvs commit: src/lib/libc/stdio fdopen.c fopen.c freopen.c X-BeenThere: cvs-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: CVS commit messages for the entire tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 27 Feb 2008 20:18:55 -0000 On Wednesday 27 February 2008 02:02:03 pm John Baldwin wrote: > 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. To reproduce, open 32k fd's and then invoke gethostbyname() with 'files' enabled in nsswitch.conf for host lookups. A fd on /etc/hosts will be leaked for each invocation of gethostbyname(). -- John Baldwin