Skip to content

Commit

Permalink
#Centipede Only update the corpus database if the binary is set.
Browse files Browse the repository at this point in the history
The corpus database update logic invokes the target binary, so the binary must
be non-empty. This also resolves the issue where we accidentally enter the
corpus database logic in the single-process mode when the corpus database flag
is set.

PiperOrigin-RevId: 651421354
  • Loading branch information
fniksic authored and copybara-github committed Jul 11, 2024
1 parent a25a874 commit 1b4a0d0
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions centipede/centipede_interface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -516,23 +516,27 @@ int CentipedeMain(const Environment &env,
const auto tmpdir = TemporaryLocalDirPath();
CreateLocalDirRemovedAtExit(tmpdir);

const std::string serialized_target_config = [&] {
ScopedCentipedeCallbacks scoped_callbacks(callbacks_factory, env);
return scoped_callbacks.callbacks()->GetSerializedTargetConfig();
}();
if (!serialized_target_config.empty()) {
const auto target_config = fuzztest::internal::Configuration::Deserialize(
serialized_target_config);
CHECK_OK(target_config.status())
<< "Failed to deserialize target configuration";
if (!target_config->corpus_database.empty()) {
CHECK(target_config->time_limit_per_test < absl::InfiniteDuration())
<< "Updating corpus database requires specifying time limit per fuzz "
"test.";
CHECK(target_config->time_limit_per_test >= absl::Seconds(1))
<< "Time limit per fuzz test must be at least 1 second.";
return UpdateCorpusDatabaseForFuzzTests(env, *target_config,
callbacks_factory);
// Enter the update corpus database mode only if we have a binary to invoke
// and a corpus database to update.
if (!env.binary.empty()) {
const std::string serialized_target_config = [&] {
ScopedCentipedeCallbacks scoped_callbacks(callbacks_factory, env);
return scoped_callbacks.callbacks()->GetSerializedTargetConfig();
}();
if (!serialized_target_config.empty()) {
const auto target_config = fuzztest::internal::Configuration::Deserialize(
serialized_target_config);
CHECK_OK(target_config.status())
<< "Failed to deserialize target configuration";
if (!target_config->corpus_database.empty()) {
CHECK(target_config->time_limit_per_test < absl::InfiniteDuration())
<< "Updating corpus database requires specifying time limit per "
"fuzz test.";
CHECK(target_config->time_limit_per_test >= absl::Seconds(1))
<< "Time limit per fuzz test must be at least 1 second.";
return UpdateCorpusDatabaseForFuzzTests(env, *target_config,
callbacks_factory);
}
}
}

Expand Down

0 comments on commit 1b4a0d0

Please sign in to comment.