Skip to content

Commit debe7d2

Browse files
author
jakehehrlich
committed
[libFuzzer] Don't prefix absolute paths in fuchsia.
The ExecuteCommand function in fuchsia used to prefix the getOutputFile for each command run with the artifact_prefix flag if it was available, because fuchsia components don't have a writable working directory. However, if a file with a global path is provided, fuchsia should honor that. An example of this is using the global /tmp directory to store stuff. In fuchsia it ended up being translated to data///tmp, whereas we want to make sure it is using /tmp (which is available to components using the isolated-temp feature). To test this I made the change, compiled fuchsia with this toolchain and ran a fuzzer with the -fork=1 flag (that mode makes use of the /tmp directory). I also tested that normal fuzzing workflow was not affected by this. Author: charco (Marco Vanotti) Differential Revision: https://reviews.llvm.org/D68774 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk/lib/fuzzer@374612 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 5d82422 commit debe7d2

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

FuzzerUtilFuchsia.cpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -407,13 +407,14 @@ int ExecuteCommand(const Command &Cmd) {
407407
// that lacks a mutable working directory. Fortunately, when this is the case
408408
// a mutable output directory must be specified using "-artifact_prefix=...",
409409
// so write the log file(s) there.
410+
// However, we don't want to apply this logic for absolute paths.
410411
int FdOut = STDOUT_FILENO;
411412
if (Cmd.hasOutputFile()) {
412-
std::string Path;
413-
if (Cmd.hasFlag("artifact_prefix"))
414-
Path = Cmd.getFlagValue("artifact_prefix") + "/" + Cmd.getOutputFile();
415-
else
416-
Path = Cmd.getOutputFile();
413+
std::string Path = Cmd.getOutputFile();
414+
bool IsAbsolutePath = Path.length() > 1 && Path[0] == '/';
415+
if (!IsAbsolutePath && Cmd.hasFlag("artifact_prefix"))
416+
Path = Cmd.getFlagValue("artifact_prefix") + "/" + Path;
417+
417418
FdOut = open(Path.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0);
418419
if (FdOut == -1) {
419420
Printf("libFuzzer: failed to open %s: %s\n", Path.c_str(),

0 commit comments

Comments
 (0)