[compiler-rt] 4caeb62 - [Fuzzer] Rename ExecuteCommandWithPopen to ExecuteCommandNon-Fushsia target will keep using popen/pclose implementation. OnFuchsia, Two-args version of `ExecuteCommand` is a simple wrapper of theone-arg version. (Hopefully) Fix D73329 build on Fuchsia.
Yuanfang Chen via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 12 16:04:27 PST 2020
Author: Yuanfang Chen
Date: 2020-02-12T16:03:55-08:00
New Revision: 4caeb62e51381446b9ddeb2508a4fc77d03fcf70
URL: https://github.com/llvm/llvm-project/commit/4caeb62e51381446b9ddeb2508a4fc77d03fcf70
DIFF: https://github.com/llvm/llvm-project/commit/4caeb62e51381446b9ddeb2508a4fc77d03fcf70.diff
LOG: [Fuzzer] Rename ExecuteCommandWithPopen to ExecuteCommandNon-Fushsia target will keep using popen/pclose implementation. OnFuchsia, Two-args version of `ExecuteCommand` is a simple wrapper of theone-arg version. (Hopefully) Fix D73329 build on Fuchsia.
Added:
Modified:
compiler-rt/lib/fuzzer/FuzzerDriver.cpp
compiler-rt/lib/fuzzer/FuzzerUtil.h
compiler-rt/lib/fuzzer/FuzzerUtilFuchsia.cpp
compiler-rt/lib/fuzzer/FuzzerUtilPosix.cpp
compiler-rt/lib/fuzzer/FuzzerUtilWindows.cpp
Removed:
################################################################################
diff --git a/compiler-rt/lib/fuzzer/FuzzerDriver.cpp b/compiler-rt/lib/fuzzer/FuzzerDriver.cpp
index c80e415130f9..0d4e468a674b 100644
--- a/compiler-rt/lib/fuzzer/FuzzerDriver.cpp
+++ b/compiler-rt/lib/fuzzer/FuzzerDriver.cpp
@@ -316,20 +316,6 @@ static std::string GetDedupTokenFromCmdOutput(const std::string &S) {
return S.substr(Beg, End - Beg);
}
-// Return true on success, false otherwise.
-static bool ExecuteCommandWithPopen(const Command &Cmd, std::string *CmdOutput) {
- FILE *Pipe = OpenProcessPipe(Cmd.toString().c_str(), "r");
- if (!Pipe)
- return false;
-
- if (CmdOutput) {
- char TmpBuffer[128];
- while (fgets(TmpBuffer, sizeof(TmpBuffer), Pipe))
- CmdOutput->append(TmpBuffer);
- }
- return CloseProcessPipe(Pipe) == 0;
-}
-
int CleanseCrashInput(const Vector<std::string> &Args,
const FuzzingOptions &Options) {
if (Inputs->size() != 1 || !Flags.exact_artifact_path) {
@@ -417,7 +403,7 @@ int MinimizeCrashInput(const Vector<std::string> &Args,
Printf("CRASH_MIN: executing: %s\n", Cmd.toString().c_str());
std::string CmdOutput;
- bool Success = ExecuteCommandWithPopen(Cmd, &CmdOutput);
+ bool Success = ExecuteCommand(Cmd, &CmdOutput);
if (Success) {
Printf("ERROR: the input %s did not crash\n", CurrentFilePath.c_str());
exit(1);
@@ -437,7 +423,7 @@ int MinimizeCrashInput(const Vector<std::string> &Args,
Cmd.addFlag("exact_artifact_path", ArtifactPath);
Printf("CRASH_MIN: executing: %s\n", Cmd.toString().c_str());
CmdOutput.clear();
- Success = ExecuteCommandWithPopen(Cmd, &CmdOutput);
+ Success = ExecuteCommand(Cmd, &CmdOutput);
Printf("%s", CmdOutput.c_str());
if (Success) {
if (Flags.exact_artifact_path) {
diff --git a/compiler-rt/lib/fuzzer/FuzzerUtil.h b/compiler-rt/lib/fuzzer/FuzzerUtil.h
index 344f2093c2d6..4ae35838306d 100644
--- a/compiler-rt/lib/fuzzer/FuzzerUtil.h
+++ b/compiler-rt/lib/fuzzer/FuzzerUtil.h
@@ -57,7 +57,9 @@ unsigned long GetPid();
size_t GetPeakRSSMb();
int ExecuteCommand(const Command &Cmd);
+bool ExecuteCommand(const Command &Cmd, std::string *CmdOutput);
+// Fuchsia does not have popen/pclose.
FILE *OpenProcessPipe(const char *Command, const char *Mode);
int CloseProcessPipe(FILE *F);
diff --git a/compiler-rt/lib/fuzzer/FuzzerUtilFuchsia.cpp b/compiler-rt/lib/fuzzer/FuzzerUtilFuchsia.cpp
index a9fff254dff0..12239c6e1b3e 100644
--- a/compiler-rt/lib/fuzzer/FuzzerUtilFuchsia.cpp
+++ b/compiler-rt/lib/fuzzer/FuzzerUtilFuchsia.cpp
@@ -533,6 +533,16 @@ int ExecuteCommand(const Command &Cmd) {
return Info.return_code;
}
+bool ExecuteCommand(const Command &BaseCmd, std::string *CmdOutput) {
+ auto LogFilePath = TempPath("SimPopenOut", ".txt");
+ Command Cmd(BaseCmd);
+ Cmd.setOutputFile(LogFilePath);
+ int Ret = ExecuteCommand(Cmd);
+ *CmdOutput = FileToString(LogFilePath);
+ RemoveFile(LogFilePath);
+ return Ret == 0;
+}
+
const void *SearchMemory(const void *Data, size_t DataLen, const void *Patt,
size_t PattLen) {
return memmem(Data, DataLen, Patt, PattLen);
diff --git a/compiler-rt/lib/fuzzer/FuzzerUtilPosix.cpp b/compiler-rt/lib/fuzzer/FuzzerUtilPosix.cpp
index a5741190a4fb..48073cfda374 100644
--- a/compiler-rt/lib/fuzzer/FuzzerUtilPosix.cpp
+++ b/compiler-rt/lib/fuzzer/FuzzerUtilPosix.cpp
@@ -86,6 +86,20 @@ static void SetSigaction(int signum,
}
}
+// Return true on success, false otherwise.
+bool ExecuteCommand(const Command &Cmd, std::string *CmdOutput) {
+ FILE *Pipe = popen(Cmd.toString().c_str(), "r");
+ if (!Pipe)
+ return false;
+
+ if (CmdOutput) {
+ char TmpBuffer[128];
+ while (fgets(TmpBuffer, sizeof(TmpBuffer), Pipe))
+ CmdOutput->append(TmpBuffer);
+ }
+ return pclose(Pipe) == 0;
+}
+
void SetTimer(int Seconds) {
struct itimerval T {
{Seconds, 0}, { Seconds, 0 }
diff --git a/compiler-rt/lib/fuzzer/FuzzerUtilWindows.cpp b/compiler-rt/lib/fuzzer/FuzzerUtilWindows.cpp
index 9d0d372fb877..b86306afddb6 100644
--- a/compiler-rt/lib/fuzzer/FuzzerUtilWindows.cpp
+++ b/compiler-rt/lib/fuzzer/FuzzerUtilWindows.cpp
@@ -161,6 +161,19 @@ int ExecuteCommand(const Command &Cmd) {
return system(CmdLine.c_str());
}
+bool ExecuteCommand(const Command &Cmd, std::string *CmdOutput) {
+ FILE *Pipe = _popen(Cmd.toString().c_str(), "r");
+ if (!Pipe)
+ return false;
+
+ if (CmdOutput) {
+ char TmpBuffer[128];
+ while (fgets(TmpBuffer, sizeof(TmpBuffer), Pipe))
+ CmdOutput->append(TmpBuffer);
+ }
+ return _pclose(Pipe) == 0;
+}
+
const void *SearchMemory(const void *Data, size_t DataLen, const void *Patt,
size_t PattLen) {
// TODO: make this implementation more efficient.
More information about the llvm-commits
mailing list