Re: If not readdir() then what?



On Sun, Apr 08, 2007 at 08:41:30PM +0200, Jörn Engel wrote:

Garbage-collecting them on closedir() does not work. It surprised me as
well, but there seem to be applications that keep the telldir() cookie
around after closedir(). Iirc, "rm -r" was one of them.

Neil, is this correct?

Well, according to the Single Unix Specification:

If the value of loc was not obtained from an earlier call to
telldir(), or if a call to rewinddir() occurred between the call
to telldir() and the call to seekdir(), the results of subsequent
calls to readdir() are unspecified.

It doesn't state explicitly that you can use the telldir cookie()
after closing the directory stream using closedir() and then reopening
it using opendir(), but given that it states that results are
undefined after a rewinddir() --- which is much less violent than a
closedir()/opendir(), I would definitely argue that an application
programmer would be very ill-advised to rely on this working.

(Of course, I'd argue that an application programmer shouldn't use
telldir/seekdir at all.....)

Ulrich, is it too late to insert a clarification that the telldir()
cookie isn't guaranteed to be valid after closedir() *or* rewinddir()?

- Ted
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



Relevant Pages

  • Re: If not readdir() then what?
    ... the question is if you can keep the seekdir/telldir cookie around ... Garbage-collecting them on closedir() does not work. ... but there seem to be applications that keep the telldir() cookie ... cookie handling between the NFS client and server. ...
    (Linux-Kernel)
  • Re: If not readdir() then what?
    ... after closing the directory stream using closedir() and then reopening ... the telldir cookie should never be valid when applied to a different DIR * ...
    (Linux-Kernel)
  • Re: If not readdir() then what?
    ... and deleted between the telldir() and seekdirpoints in time makes ... the question is if you can keep the seekdir/telldir cookie around ... but then you're succeptible to a memory allocation attack. ... interface, at least until the use of telldir/seekdir had actually ...
    (Linux-Kernel)
  • Re: If not readdir() then what?
    ... H. Peter Anvin wrote: ... a stupid thing to do. ... platforms) telldir returns a 64-bit cookie. ... big issue is that there are no error values for telldir. ...
    (Linux-Kernel)