diff options
author | Matt Morehouse <mascasa@google.com> | 2017-12-04 19:25:59 +0000 |
---|---|---|
committer | Matt Morehouse <mascasa@google.com> | 2017-12-04 19:25:59 +0000 |
commit | 7c02ae4470ce8c0cb75b9974861a36fd259cbf74 (patch) | |
tree | 19b9e1e17bb6f17ff91e3a1647961d096abd4637 /compiler-rt/lib/fuzzer/FuzzerUtilDarwin.cpp | |
parent | 67ce8fd4262bb634aa15f108bfeb7f5a637e646c (diff) |
[libFuzzer] Encapsulate commands in a class.
Summary:
To be more portable (especially w.r.t. platforms without system()),
commands should be managed programmatically rather than via string
manipulation on the command line. This change introduces
Fuzzer::Command, with methods to manage arguments and flags, set output
options, and execute the command.
Patch By: aarongreen
Reviewers: kcc, morehouse
Reviewed By: kcc, morehouse
Subscribers: llvm-commits, mgorny
Differential Revision: https://reviews.llvm.org/D40103
Diffstat (limited to 'compiler-rt/lib/fuzzer/FuzzerUtilDarwin.cpp')
-rw-r--r-- | compiler-rt/lib/fuzzer/FuzzerUtilDarwin.cpp | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/compiler-rt/lib/fuzzer/FuzzerUtilDarwin.cpp b/compiler-rt/lib/fuzzer/FuzzerUtilDarwin.cpp index 2df4872a920..4bfbc11a50c 100644 --- a/compiler-rt/lib/fuzzer/FuzzerUtilDarwin.cpp +++ b/compiler-rt/lib/fuzzer/FuzzerUtilDarwin.cpp @@ -10,7 +10,7 @@ //===----------------------------------------------------------------------===// #include "FuzzerDefs.h" #if LIBFUZZER_APPLE - +#include "FuzzerCommand.h" #include "FuzzerIO.h" #include <mutex> #include <signal.h> @@ -38,7 +38,8 @@ static sigset_t OldBlockedSignalsSet; // signal handlers when the first thread enters and restores them when the last // thread finishes execution of the function and ensures this is not racey by // using a mutex. -int ExecuteCommand(const std::string &Command) { +int ExecuteCommand(const Command &Cmd) { + std::string CmdLine = Cmd.toString(); posix_spawnattr_t SpawnAttributes; if (posix_spawnattr_init(&SpawnAttributes)) return -1; @@ -98,7 +99,7 @@ int ExecuteCommand(const std::string &Command) { pid_t Pid; char **Environ = environ; // Read from global - const char *CommandCStr = Command.c_str(); + const char *CommandCStr = CmdLine.c_str(); char *const Argv[] = { strdup("sh"), strdup("-c"), |