summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/lib/Fuzzer/FuzzerIO.h3
-rw-r--r--llvm/lib/Fuzzer/FuzzerIOPosix.cpp6
-rw-r--r--llvm/lib/Fuzzer/FuzzerIOWindows.cpp2
-rw-r--r--llvm/lib/Fuzzer/FuzzerMerge.cpp4
4 files changed, 13 insertions, 2 deletions
diff --git a/llvm/lib/Fuzzer/FuzzerIO.h b/llvm/lib/Fuzzer/FuzzerIO.h
index 741fecf415b..15bfd3d3472 100644
--- a/llvm/lib/Fuzzer/FuzzerIO.h
+++ b/llvm/lib/Fuzzer/FuzzerIO.h
@@ -37,6 +37,9 @@ std::string DirPlusFile(const std::string &DirPath,
// Returns the name of the dir, similar to the 'dirname' utility.
std::string DirName(const std::string &FileName);
+// Returns path to a TmpDir.
+std::string TmpDir();
+
void DupAndCloseStderr();
void CloseStdout();
diff --git a/llvm/lib/Fuzzer/FuzzerIOPosix.cpp b/llvm/lib/Fuzzer/FuzzerIOPosix.cpp
index 720bc130459..6d8edf6ff53 100644
--- a/llvm/lib/Fuzzer/FuzzerIOPosix.cpp
+++ b/llvm/lib/Fuzzer/FuzzerIOPosix.cpp
@@ -83,6 +83,12 @@ std::string DirName(const std::string &FileName) {
return Res;
}
+std::string TmpDir() {
+ if (auto Env = getenv("TMPDIR"))
+ return Env;
+ return "/tmp";
+}
+
} // namespace fuzzer
#endif // LIBFUZZER_POSIX
diff --git a/llvm/lib/Fuzzer/FuzzerIOWindows.cpp b/llvm/lib/Fuzzer/FuzzerIOWindows.cpp
index a4738eb9dfe..056f0721a33 100644
--- a/llvm/lib/Fuzzer/FuzzerIOWindows.cpp
+++ b/llvm/lib/Fuzzer/FuzzerIOWindows.cpp
@@ -277,6 +277,8 @@ std::string DirName(const std::string &FileName) {
return FileName.substr(0, LocationLen + DirLen);
}
+std::string TmpDir() { return "TODO: implement TmpDir"; }
+
} // namespace fuzzer
#endif // LIBFUZZER_WINDOWS
diff --git a/llvm/lib/Fuzzer/FuzzerMerge.cpp b/llvm/lib/Fuzzer/FuzzerMerge.cpp
index 84660e0fe53..b3d46435fcd 100644
--- a/llvm/lib/Fuzzer/FuzzerMerge.cpp
+++ b/llvm/lib/Fuzzer/FuzzerMerge.cpp
@@ -220,8 +220,8 @@ void Fuzzer::CrashResistantMerge(const std::vector<std::string> &Args,
ListFilesInDirRecursive(Corpora[i], nullptr, &AllFiles, /*TopDir*/true);
Printf("MERGE-OUTER: %zd files, %zd in the initial corpus\n",
AllFiles.size(), NumFilesInFirstCorpus);
- std::string CFPath =
- "libFuzzerTemp." + std::to_string(GetPid()) + ".txt";
+ auto CFPath = DirPlusFile(TmpDir(),
+ "libFuzzerTemp." + std::to_string(GetPid()) + ".txt");
// Write the control file.
RemoveFile(CFPath);
std::ofstream ControlFile(CFPath);
OpenPOWER on IntegriCloud