From owner-freebsd-standards@FreeBSD.ORG Fri Jan 24 18:06:41 2014 Return-Path: Delivered-To: freebsd-standards@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 90D26828; Fri, 24 Jan 2014 18:06:41 +0000 (UTC) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id EB1B419CC; Fri, 24 Jan 2014 18:06:40 +0000 (UTC) Received: from tom.home (kostik@localhost [127.0.0.1]) by kib.kiev.ua (8.14.7/8.14.7) with ESMTP id s0OI6Z2k069531; Fri, 24 Jan 2014 20:06:35 +0200 (EET) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.8.3 kib.kiev.ua s0OI6Z2k069531 Received: (from kostik@localhost) by tom.home (8.14.7/8.14.7/Submit) id s0OI6ZoA069530; Fri, 24 Jan 2014 20:06:35 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Fri, 24 Jan 2014 20:06:35 +0200 From: Konstantin Belousov To: Bryan Drewery Subject: Re: closedir(3) handling NULL Message-ID: <20140124180635.GN24664@kib.kiev.ua> References: <20140124014105.GC37334@admin.xzibition.com> <20140124132435.GA90996@stack.nl> <20140124165509.GA73838@admin.xzibition.com> <20140124172123.GK24664@kib.kiev.ua> <20140124174938.GB73838@admin.xzibition.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="YuJye9aIuN0w6xGV" Content-Disposition: inline In-Reply-To: <20140124174938.GB73838@admin.xzibition.com> User-Agent: Mutt/1.5.22 (2013-10-16) X-Spam-Status: No, score=-2.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED autolearn=no version=3.3.2 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on tom.home Cc: bapt@FreeBSD.org, freebsd-standards@FreeBSD.org, Jilles Tjoelker X-BeenThere: freebsd-standards@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: Standards compliance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 24 Jan 2014 18:06:41 -0000 --YuJye9aIuN0w6xGV Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Jan 24, 2014 at 11:49:39AM -0600, Bryan Drewery wrote: > On Fri, Jan 24, 2014 at 07:21:23PM +0200, Konstantin Belousov wrote: > > On Fri, Jan 24, 2014 at 10:55:09AM -0600, Bryan Drewery wrote: > > > On Fri, Jan 24, 2014 at 02:24:35PM +0100, Jilles Tjoelker wrote: > > > > On Thu, Jan 23, 2014 at 07:41:05PM -0600, Bryan Drewery wrote: > > > > > I found that Linux handles closedir(NULL) fine and returns EINVAL= =2E POSIX > > > > > [1] specifies that EBADF should be returned if "The dirp argument= does > > > > > not refer to an open directory stream" > > > >=20 > > > > > [1] http://pubs.opengroup.org/onlinepubs/009696799/functions/clos= edir.html > > > >=20 > > > > > I've updated fdclosedir(3) as well to behave the same. > > > >=20 > > > > > I'll also update the manpage if there is no objection. > > > >=20 > > > > If you do this, it is to improve compatibility with poorly written > > > > software and not for POSIX compliance. POSIX only permits passing n= ull > > > > pointers where explicitly specified (e.g. time()); otherwise, passi= ng a > > > > null pointer is undefined behaviour like passing any argument outsi= de > > > > the required domain. > > >=20 > > > I do think that improving portability is important. Even against slop= py > > > coding. Applications developed for Linux are fine passing NULL to clo= sedir(3), > > > which leads to a style of coding that does not reveal itself to be a > > > problem on FreeBSD until an edge case comes up. > > >=20 > > > This is the situation to led to me find this. A mountpoint disappeared > > > and some code written for Linux, that ported to FreeBSD without chang= es, > > > segfaulted in closedir(3). > > This is somewhat strange description of events, it definitely misses > > some intermediate steps. The mere fact of unmounting does not change > > anonymous memory content of some application. Even if the DIR * was > > assotiated with the directory descriptor belonging to the disappeared > > mount point, the DIR * and file descriptors are still valid, although > > not that functional. >=20 > The code constructed a path, called opendir(3), received NULL, skipped > over code that uses the entry since it was NULL, then called > closedir(3). >=20 > Also, I don't find this very different than free(3) with a NULL. It's > considered bad practice to check for NULL before calling it, why is > closedir(3) any different? Ok, so it does not have much to do with unmount, it is just an open of nonexistent path. I do not have an answer to the question about free(3), except that free(NULL) behaviour is required by ANSI C, while closedir(NULL) is not, by posix. --YuJye9aIuN0w6xGV Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (FreeBSD) iQIcBAEBAgAGBQJS4quqAAoJEJDCuSvBvK1BOxcP/0HhDJ+9Ao2cRO+c74eDpqKC ZH2lbY439MnNc321rZL5wgKQoFFWJ6Wsr9iTuSnN5Mz++HHcz1gkIJ4b5EeZ+CXI JS+VsM2nRSZHEFTrY6Lf6XX8TosBv4eFEyTHQTiIll6oAta4sjA6DieOjwNXmlh/ ggTdmpymZxDofHAMWR+bOYq0yUTJ/kdAVu5OT6iKlgenEwaNY2wweTZdjq/a/cGH 6YS8o48MH14ohvXaw9icdlqaiqvswgvJxT+SrQfdxSCPSbP+cdSR3hGnfoGLICBU At/B/XlJT9HdLz81q9t/W1ULnof8YPP5NOU9MNBf2tazEwiOrAIIJ54WPQdNJnF4 DxbwHFyXGIV0zP8M7cdA42ZJw0rIIlu7ua53lBwjCPhzIBLYexVWrf5qx/eiJ9cy 4UbKlUFwQB+4wbjizX6lTElUka0APAMaIc5zS1iNUBOsDvsLCf8UubWBjPgHvGBH bE3zDLX5K4InyEVN64t/oLiyyddyWNdHPPZm5lFAERY7jRFCL5jGTd+Z8jAAVwGh E+JQ5qFF7i6fYWjalB7qFZt+0ZiBMnxRarqgtC7aMpyBJqHukG3asZs7OeypeBcE ZIs30y6O0ps3xdXRDY4SribKNX05HklzOpGHx1P4qr1xuJpiDDd8/S8Wd9hXgMRW FCjLdw5oFm17AbcqI6d+ =ZTYs -----END PGP SIGNATURE----- --YuJye9aIuN0w6xGV--