From owner-freebsd-standards@FreeBSD.ORG Fri Jan 24 17:49:43 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 73DCE292 for ; Fri, 24 Jan 2014 17:49:43 +0000 (UTC) Received: from secure.xzibition.com (secure.xzibition.com [173.160.118.92]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 235CD1853 for ; Fri, 24 Jan 2014 17:49:43 +0000 (UTC) DomainKey-Signature: a=rsa-sha1; c=nofws; d=shatow.net; h=date:from:to :cc:subject:message-id:references:mime-version:content-type :in-reply-to; q=dns; s=sweb; b=QtGaIQC7hi2Z9yPx14yuek+29BGaP3ER0 gERBABtktUArnAbIXiqFuQ/Q6gdctMt2irbwkceu8nPYTM6n8vJTnFXNIbf7xj1C 2BF+b9zWyWuoCM4eXnCOoNJ7XOIatSPChDc3ogvH+WjaXn5naf/UIQthQ8J0z5J/ K6XaJtbxRQ= DKIM-Signature: v=1; a=rsa-sha256; c=simple; d=shatow.net; h=date:from :to:cc:subject:message-id:references:mime-version:content-type :in-reply-to; s=sweb; bh=szqdAY/lfJwMd6pBhGz82JO771RpomiBKn1G5vC uopo=; b=UPyOhm7fUC//7YSKmaYGB0sgDDRL4PQ4vclQC3uq+K2N9Cv9jIFMrGx yFiaoy8gIEtSyGd7IqVIr85gHg3wrwtdkOve/W5iHeFJhsskmpkAOjY6o28Y8U4f Z23AkKJrakHcjgRkB0ifTd5yksucNBIuKcBq1TOQN2R+n6C78gOM= Received: (qmail 53688 invoked from network); 24 Jan 2014 11:49:40 -0600 Received: from unknown (HELO admin.xzibition.com) (bryan@shatow.net@173.160.118.90) by sweb.xzibition.com with ESMTPA; 24 Jan 2014 11:49:40 -0600 Date: Fri, 24 Jan 2014 11:49:39 -0600 From: Bryan Drewery To: Konstantin Belousov Subject: Re: closedir(3) handling NULL Message-ID: <20140124174938.GB73838@admin.xzibition.com> References: <20140124014105.GC37334@admin.xzibition.com> <20140124132435.GA90996@stack.nl> <20140124165509.GA73838@admin.xzibition.com> <20140124172123.GK24664@kib.kiev.ua> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="7iMSBzlTiPOCCT2k" Content-Disposition: inline In-Reply-To: <20140124172123.GK24664@kib.kiev.ua> User-Agent: Mutt/1.5.22 (2013-10-16) 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 17:49:43 -0000 --7iMSBzlTiPOCCT2k Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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. = POSIX > > > > [1] specifies that EBADF should be returned if "The dirp argument d= oes > > > > not refer to an open directory stream" > > >=20 > > > > [1] http://pubs.opengroup.org/onlinepubs/009696799/functions/closed= ir.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 null > > > pointers where explicitly specified (e.g. time()); otherwise, passing= a > > > null pointer is undefined behaviour like passing any argument outside > > > the required domain. > >=20 > > I do think that improving portability is important. Even against sloppy > > coding. Applications developed for Linux are fine passing NULL to close= dir(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 changes, > > 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. 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). 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? Regards, Bryan Drewery --7iMSBzlTiPOCCT2k Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (FreeBSD) iQJ8BAEBCgBmBQJS4qeyXxSAAAAAAC4AKGlzc3Vlci1mcHJAbm90YXRpb25zLm9w ZW5wZ3AuZmlmdGhob3JzZW1hbi5uZXQzNkZFQkU5OTJGNTI4MERGNDgxMTM2MkE2 RTc4MkFDMDNDOUIwQ0Y5AAoJEG54KsA8mwz5pnEQAJnXxJWcElWv/ZRvwPyldug2 PDVrabYk6w5aaFPkINHm8GrNveQJMa7w6zvZGNpMpGhJgvNwSPjNxHVckrv6fN8M duKHGMfgun9VuoSYwzxX9fBIu0UNDywFm7BIbiRnwFotRY6BxE35K9/8EW29bU3Q V6Zy/LQv4uVFpkMafFX0OAnPS7TRRcGRNRoHlJPfRXu8Qd7IjcE2uEqyOmQ0KPlA BVL936xfAFuNfQJR4vdSsoOyRpSyLC1Cf8ewtlJHJkgnppX4IB/M1x6wd4mjHJvL 7sMBNmdEyu/Wjdr8m8+aX4WQdW756ZR2+MAKJWlUGvPqprDKnDg1cM5Tuh5iXLjX ilZ8RLLrYt5BJU+0e+LUCDGEoiNh7lYkC5Gu1d2d7MF/axqMHR4OYFfbBrMq4pzj SEa5y4QNzxEoIth9yRCxB321XQZ+9LkiYM90FS+Frc+GH+Jx57hVbB4FWEDNkxxJ YqKr7Ka1Ij+DDHJmeAiLHSxXRPQ4RCnjR+llI8zKr5d8wmed/h+ADdDqv3zmHXk/ oMOEiG9F/89472r0jG27rOM9IXcoxNapW/H8OMoH2NsNNuoC4hnZK6YHATuXeCGx XluC4L7BRllInPL/iI0IFy0i7peTjioNyocQ+Bh6o0fPTV82DKgGpjEaJKi99tJF aOP2s6dN2AJVKV+rnfZC =xlaf -----END PGP SIGNATURE----- --7iMSBzlTiPOCCT2k--