Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 24 Jan 2014 11:49:39 -0600
From:      Bryan Drewery <bryan@shatow.net>
To:        Konstantin Belousov <kostikbel@gmail.com>
Cc:        bapt@FreeBSD.org, freebsd-standards@FreeBSD.org, Jilles Tjoelker <jilles@stack.nl>
Subject:   Re: closedir(3) handling NULL
Message-ID:  <20140124174938.GB73838@admin.xzibition.com>
In-Reply-To: <20140124172123.GK24664@kib.kiev.ua>
References:  <20140124014105.GC37334@admin.xzibition.com> <20140124132435.GA90996@stack.nl> <20140124165509.GA73838@admin.xzibition.com> <20140124172123.GK24664@kib.kiev.ua>

next in thread | previous in thread | raw e-mail | index | archive | help

--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--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20140124174938.GB73838>