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 12:10:42 -0800
From: enh <>
To: Florian Weimer <>
Cc:, Rich Felker <>
Subject: Re: Lifetime of object returned by readdir

On Tue, Feb 23, 2021 at 10:32 AM Florian Weimer <> wrote:

> > POSIX already explicitly says that seekdir() affects the _next_
> > readdir().
> That's because it's the only way its effect is observable.
> The glibc implementation of seekdir performs an immediate seek, but if
> the seek fails, that error is not really observable (except for reading
> the implementation and inferring that the errno = 0 hack will work).  I
> had not realized that seekdir returns void.  Maybe that argues in favor
> of a delayed seek upon the next readdir call.
> > does anyone have an implementation where rewinddir()/seekdir()
> > actually invalidate the previous readdir()? seems unlikely?
> Probably not.  But there's also the issue of fitting the directory
> offset (usually off64_t, maybe even something larger) into the long int
> return value of telldir, so there could be quite a bit of magic going on
> in the background (considering that telldir cannot indicate failure).

i suspect anyone iterating over a directory that large has other problems

fwiw, the only calls to telldir() or seekdir() in Android (not counting any
vendor blobs i can't see the source to) are in the bionic unit tests and
other languages' runtime wrappers (rust/python).

there are < 10 uses of rewinddir(), and < 5 if you don't count tests. (and
at least one of those is directly following an opendir() :-/ )

> Thanks,
> Florian

Content of type "text/html" skipped

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.