[41100] in bugtraq

home help back first fref pref prev next nref lref last post

Re: [Full-disclosure] Re: readdir_r considered harmful

daemon@ATHENA.MIT.EDU (Andrew Miller)
Tue Nov 8 13:33:37 2005

Message-ID: <437003A6.4020502@amxl.com>
Date: Tue, 08 Nov 2005 14:47:18 +1300
From: Andrew Miller <andrew@amxl.com>
MIME-Version: 1.0
To: bugtraq@securityfocus.com
Cc: drepper@gmail.com, Casper.Dik@sun.com, full-disclosure@lists.grok.org.uk
In-Reply-To: <200511061919.jA6JJjDk000766@vaticaan.Holland.Sun.COM>
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

Casper.Dik@Sun.COM wrote:
...

>Had they done so, we would never have had to use readdir_r() and progammers
>would not have introduced bugs in the (mis)use of pathconf, over allocating,
>etc.
>
>I would be interested in seeing any real-world use of readdir_r() in
>a context where readdir_r() is required (multiple threads reading from
>a single DIR *).
>  
>
Consider the following situation(I'm not sure if anyone actually does this):
1) You have a "spool" directory containing a large number of files, each
which represents a task to process.
2) You have a number of worker threads. Each worker thread reads a file
from the global DIR*, and then opens and reads the file for
processing(and then loops on 2).

Of course, you could always just put a mutex around every call to
readdir(), and copy the filename somewhere safe, or you could invent a
signalling system to ask one thread to do all the readdir()s. Whether
this makes sense depends on how much of readdir_r has to be spent inside
a global mutex/spinlock anyway, and how long the processing part takes
compared with the readdir() part.

Andrew


home help back first fref pref prev next nref lref last post