Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Tue, 23 Feb 2021 17:01:03 -0800
From: "Joshua M. Clulow" <josh@...mgr.org>
To: libc-coord@...ts.openwall.com
Subject: Re: Lifetime of object returned by readdir

On Tue, 23 Feb 2021 at 09:16, Rich Felker <dalias@...c.org> wrote:
> This leaves "part of the storage associated with the DIR stream
> object" as the only reasonable place for the dirent to live, and of
> course that's the natural (for zerocopy) place for it to live anyway,
> and where it does live in existing implementations (at least glibc and
> musl).

This is also true for illumos.  We return, from readdir(3C), pointers
to the buffer in the DIR object:

    http://src.illumos.org/source/xref/illumos-gate/usr/src/lib/libc/port/gen/readdir.c?r=7257d1b4#61-84

And we free it all (the DIR and the buffer) at closedir(3C):

    http://src.illumos.org/source/xref/illumos-gate/usr/src/lib/libc/port/gen/closedir.c?r=7257d1b4&mo=1374&fi=49#48-58

> I'd like to push to have this fixed (adding closedir as a condition
> that ends the lifetime) as part of making readdir thread-safe, but
> before opening a new Austin Group issue or following up on the
> existing one there I'd like to make sure we're on the same page.

That makes sense to me, and would match our implementation.  Our
manual pages don't currently explicitly call this behaviour out, but
it really seems like they should so I've filed a bug:

    https://www.illumos.org/issues/13579


Cheers.

-- 
Joshua M. Clulow
http://blog.sysmgr.org

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.