From owner-svn-src-projects@FreeBSD.ORG Thu Sep 1 20:37:34 2011 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 9FFAB1065675; Thu, 1 Sep 2011 20:37:34 +0000 (UTC) (envelope-from jilles@stack.nl) Received: from mx1.stack.nl (relay02.stack.nl [IPv6:2001:610:1108:5010::104]) by mx1.freebsd.org (Postfix) with ESMTP id 359478FC15; Thu, 1 Sep 2011 20:37:34 +0000 (UTC) Received: from turtle.stack.nl (turtle.stack.nl [IPv6:2001:610:1108:5010::132]) by mx1.stack.nl (Postfix) with ESMTP id C16783593E1; Thu, 1 Sep 2011 22:37:32 +0200 (CEST) Received: by turtle.stack.nl (Postfix, from userid 1677) id B881C17416; Thu, 1 Sep 2011 22:37:32 +0200 (CEST) Date: Thu, 1 Sep 2011 22:37:32 +0200 From: Jilles Tjoelker To: Sergey Kandaurov Message-ID: <20110901203732.GA98596@stack.nl> References: <201108222354.p7MNsC9B074753@svn.freebsd.org> <20110824211427.GB96070@stack.nl> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Cc: svn-src-projects@freebsd.org, gk@freebsd.org, src-committers@freebsd.org, Matthew D Fleming Subject: Re: svn commit: r225097 - in projects/ino64: include lib/libc/gen usr.sbin/cpucontrol usr.sbin/lpr/common_source usr.sbin/newsyslog X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 01 Sep 2011 20:37:34 -0000 On Thu, Sep 01, 2011 at 07:32:06PM +0400, Sergey Kandaurov wrote: > On 25 August 2011 01:14, Jilles Tjoelker wrote: > > On Mon, Aug 22, 2011 at 11:54:12PM +0000, Matthew D Fleming wrote: > >> Author: mdf > >> Date: Mon Aug 22 23:54:12 2011 > >> New Revision: 225097 > >> URL: http://svn.freebsd.org/changeset/base/225097 > >> Log: > >>   Avoid using dirfd name there is dirfd() macro already. > >>   Use dirfd() instead of dirp->dd_fd. > >>   Replace dirfd() macro with exported libc symbol. > >>   Use _dirfd() macro internally. > >>   GSoC r222835, r222836, r222837. > >>   Code by Gleb Kurtsou. > >> Added: projects/ino64/lib/libc/gen/dirfd.c > >> ============================================================================== > >> --- /dev/null 00:00:00 1970   (empty, because file is newly added) > >> +++ projects/ino64/lib/libc/gen/dirfd.c       Mon Aug 22 23:54:12 2011        (r225097) > > [snip] > >> +int > >> +dirfd(DIR *dirp) > >> +{ > >> +     if (dirp == NULL) > >> +             return (-1); > >> + > >> +     return (_dirfd(dirp)); > >> +} > > Why have this check here? I think the original behaviour (a segfault) is > > more useful here since the return value of this interface is often not > > checked. > Why not to convert it to EINVAL? > As per IEEE Std 1003.1-2008: > The dirfd() function may fail if: > [EINVAL] > The dirp argument does not refer to a valid directory stream. Given that this error is optional and that there is no other mention of this condition, I think the undefined behaviour for a function argument outside the permitted domain still applies. Also, glibc and OpenSolaris dirfd() likewise segfault if passed a null pointer. A Google code search suggested that the interface is often used without checking (for example, passing the result directly to fchdir() or a *at function) and in that case returning -1 for a NULL pointer makes the problem harder to diagnose (fortunately, AT_FDCWD is not -1 so a *at function will at least fail with EBADF, like fchdir()). -- Jilles Tjoelker