summaryrefslogtreecommitdiff
path: root/compiler-rt/lib/fuzzer/FuzzerIOPosix.cpp
diff options
context:
space:
mode:
authorKostya Serebryany <kcc@google.com>2017-11-15 16:45:17 +0000
committerKostya Serebryany <kcc@google.com>2017-11-15 16:45:17 +0000
commitb80d86d84bdfa155a55fdaeb5d37f1a53d6df1d5 (patch)
tree635324443bcab1dd786c33cced7db1c368b21491 /compiler-rt/lib/fuzzer/FuzzerIOPosix.cpp
parent34698554289070aac36a3a50bc782002f9afac3f (diff)
libfuzzer: Fix file listing on some filesystems
Summary: For some filesystems, readdir will not populate dirent::d_type with valuable information. This causes libfuzzer to proceed with an empty corpus, instead of the file it contains. This has been tested on a server using XFS. It should fix https://bugs.llvm.org//show_bug.cgi?id=25991 Reviewers: kcc Reviewed By: kcc Differential Revision: https://reviews.llvm.org/D40028
Diffstat (limited to 'compiler-rt/lib/fuzzer/FuzzerIOPosix.cpp')
-rw-r--r--compiler-rt/lib/fuzzer/FuzzerIOPosix.cpp14
1 files changed, 12 insertions, 2 deletions
diff --git a/compiler-rt/lib/fuzzer/FuzzerIOPosix.cpp b/compiler-rt/lib/fuzzer/FuzzerIOPosix.cpp
index 2c452a7dd8d..9d2f6119e9a 100644
--- a/compiler-rt/lib/fuzzer/FuzzerIOPosix.cpp
+++ b/compiler-rt/lib/fuzzer/FuzzerIOPosix.cpp
@@ -32,6 +32,13 @@ bool IsFile(const std::string &Path) {
return S_ISREG(St.st_mode);
}
+static bool IsDirectory(const std::string &Path) {
+ struct stat St;
+ if (stat(Path.c_str(), &St))
+ return false;
+ return S_ISDIR(St.st_mode);
+}
+
size_t FileSize(const std::string &Path) {
struct stat St;
if (stat(Path.c_str(), &St))
@@ -52,9 +59,12 @@ void ListFilesInDirRecursive(const std::string &Dir, long *Epoch,
}
while (auto E = readdir(D)) {
std::string Path = DirPlusFile(Dir, E->d_name);
- if (E->d_type == DT_REG || E->d_type == DT_LNK)
+ if (E->d_type == DT_REG || E->d_type == DT_LNK ||
+ (E->d_type == DT_UNKNOWN && IsFile(Path)))
V->push_back(Path);
- else if (E->d_type == DT_DIR && *E->d_name != '.')
+ else if ((E->d_type == DT_DIR ||
+ (E->d_type == DT_UNKNOWN && IsDirectory(Path))) &&
+ *E->d_name != '.')
ListFilesInDirRecursive(Path, Epoch, V, false);
}
closedir(D);