mirror of
https://github.com/chromium/crashpad.git
synced 2024-12-28 15:50:26 +08:00
1abaf22e28
readdir_r() is a thread-safe version of readdir(), although readdir() is not particularly thread-unsafe with most usage. The dirent* returned by readdir() can only be invalidated by a subsequent readdir() or closedir() on the same DIR*. In typical usage, where a returned dirent* is used exclusively within a loop around readdir() and is not expected to outlive that loop, there are no lifetime or thread-safety issues with the use of readdir(). readdir_r() may be harmful in certain situations because its buffer is not explicitly sized, and attempts to provide a suitably sized buffer dynamically (which, incidentally, our code did not do) are subject to a race condition. https://elliotth.blogspot.com/2012/10/how-not-to-use-readdirr3.html https://womble.decadent.org.uk/readdir_r-advisory.html glibc has already deprecated readdir_r(), and all Linux (including Android) code was already using readdir(). This change eliminates variant codepaths. It delegates buffer sizing (which we weren’t doing correctly) to the C library, which also has more options at its disposal to avoid races in sizing that buffer. Change-Id: I4fca8948454116360180ad0017f226d06727ef81 Reviewed-on: https://chromium-review.googlesource.com/705756 Reviewed-by: Joshua Peraza <jperaza@chromium.org>