Some Boost.Filesystem problems

I noticed that Boost.Filesystem doesn't use readdir_r to iterate over directories, even if it is available, making that non-thread-safe. There is a comment to this effect in operations_posix_windows.cpp. I've attached a patch that I believe will allow it to detect whether readdir_r is available and to use it iff it is. I have only tested this on Linux with g++ 3.3, but I tried deliberately breaking the declaration of readdir_r and verified that the code continues to work without it. On a visual inspection some time back I also noted that there's no special handling for empty root directories on Windows. The problem with these is that while even an empty directory normally has entries for "." and "..", so that FindFirstFile can return something, root directories on FAT volumes (and I think NTFS as well) do not have these and Windows doesn't fake them, so FindFirstFile on an empty root returns INVALID_HANDLE_VALUE. Note that this only applies to real root directories, not to the roots of drives that are mapped to sub-directories using subst or file sharing. I never got round to checking whether the Boost code actually handles this or not, as I only use Windows at work and we don't use Boost.Filesystem there. Perhaps someone could check that out? Unfortunately it's impractical to test automatically, as empty volumes are hard to generate on demand! Ben. -- Ben Hutchings DNRC Motto: I can please only one person per day. Today is not your day. Tomorrow isn't looking good either.

I wrote:
+ // The required buffer size is the size that struct dirent would + // have were its d_name array to be long enough - which it might + // not be. + const std::size_t buf_len = sizeof( struct dirent ) + - sizeof( ( (struct dirent *) 0 )->d_name ) + + ::pathconf( dir, _PC_NAME_MAX ) + 1;
Oops, this isn't safe; there's a potential race condition that could result in buffer overflow. Replace the pathconf call-expression with just NAME_MAX and it should be OK. Ben. -- Ben Hutchings Klipstein's 4th Law of Prototyping and Production: A fail-safe circuit will destroy others.
participants (1)
-
Ben Hutchings