Skip to content

Commit e3d35b9

Browse files
hadi88copybara-github
authored andcommitted
Use the output directory for relative corpus path when fuzzing.
PiperOrigin-RevId: 835240175
1 parent 1c3e6d1 commit e3d35b9

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

fuzztest/init_fuzztest.cc

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -348,10 +348,20 @@ internal::Configuration CreateConfigurationsFromFlags(
348348
<< "If specified, --" << FUZZTEST_FLAG(jobs).Name()
349349
<< " must be positive.";
350350
std::string corpus_database = absl::GetFlag(FUZZTEST_FLAG(corpus_database));
351-
if (!corpus_database.empty() && corpus_database[0] != '/' &&
352-
std::getenv("TEST_SRCDIR")) {
353-
corpus_database =
354-
absl::StrCat(std::getenv("TEST_SRCDIR"), "/", corpus_database);
351+
if (!corpus_database.empty() && corpus_database[0] != '/') {
352+
// When fuzzing, pick the undeclared output directory for a relative corpus
353+
// database path, because the output directory is writable. Otherwise, pick
354+
// the test srcdir (read-only) as the current directory when dealing with a
355+
// relative corpus database path.
356+
if (fuzzing_time_limit) { // Need a writable directory.
357+
if (std::getenv("TEST_UNDECLARED_OUTPUTS_DIR")) {
358+
corpus_database = absl::StrCat(
359+
std::getenv("TEST_UNDECLARED_OUTPUTS_DIR"), "/", corpus_database);
360+
}
361+
} else if (std::getenv("TEST_SRCDIR")) { // Need a read-only directory.
362+
corpus_database =
363+
absl::StrCat(std::getenv("TEST_SRCDIR"), "/", corpus_database);
364+
}
355365
}
356366
return internal::Configuration{
357367
corpus_database,

0 commit comments

Comments
 (0)