On Thu, Apr 27, 2017 at 01:53:44PM +0100, Richard Ipsum wrote:
> I'd very much like to see a patch resolving what you see as the issue regarding
> a name exceeding NAME_MAX. TBH I'd be quite satisfied with something which
> caused an error return if the d_name array lacked a terminator, though if you
> can come up with something which can recover things, that'd be awesome too.
> I think this might be related to https://trello.com/c/BeeWV4Ej/50
Okay I'll look into it.
After more reading around I'm less convinced there's much real benefit
in persevering with readdir_r. Firstly, the BSDs lock the dir stream
if the code is executing in a thread. Secondly, even Solaris
says readdir is preferred and says it's safe to read dirs in a threaded
application so long as different threads use different streams:
It is safe to use readdir() in a threaded application,
so long as only one thread reads from the directory stream at any given time.
The readdir() function is generally preferred over the readdir_r() function.
Thirdly, trying to use readdir_r correctly in a platform independent way
seems to be almost impossible, after all this reading around I'm convinced
it's more trouble than it's worth and I suspect that's why it's now
Imo, the ideal solution would be to use readdir by default, thereby avoiding
this potential heap/stack smashing readdir_r issue, provide a separate
call for those people who, for whatever reason, really need to use readdir_r,
and make it clear in the documentation what a total mess the situation is.