about summary refs log tree commit diff
path: root/utils/optimin/src/OptiMin.cpp
diff options
context:
space:
mode:
authorAdrian Herrera <adrian.herrera02@gmail.com>2021-07-26 02:11:21 +0000
committerAdrian Herrera <adrian.herrera02@gmail.com>2021-07-28 06:50:41 +0000
commitcc933bcc0c63df22df981ef991582170d40fbb95 (patch)
treee6ef6c9a51343db7d6fb155e4895b4f49a888da9 /utils/optimin/src/OptiMin.cpp
parent33f9f911c13cfd513366b7b1c9f9c66c0aa944f7 (diff)
downloadafl++-cc933bcc0c63df22df981ef991582170d40fbb95.tar.gz
optimin: support afl-cmin crash mode
Diffstat (limited to 'utils/optimin/src/OptiMin.cpp')
-rw-r--r--utils/optimin/src/OptiMin.cpp20
1 files changed, 14 insertions, 6 deletions
diff --git a/utils/optimin/src/OptiMin.cpp b/utils/optimin/src/OptiMin.cpp
index 4f88b897..276f6b0f 100644
--- a/utils/optimin/src/OptiMin.cpp
+++ b/utils/optimin/src/OptiMin.cpp
@@ -212,9 +212,14 @@ static Error getAFLCoverage(const StringRef Seed, AFLCoverageVector &Cov,
   // Run afl-showmap
   const int RC = sys::ExecuteAndWait(AFLShowmapPath, AFLShowmapArgs,
                                      /*env=*/None, Redirects);
-  if (RC)
+  if (RC && !CrashMode) {
+
+    ErrMsg() << "Exit code " << RC << " != 0 received from afl-showmap";
+    sys::fs::remove(TracePath);
     return createStringError(inconvertibleErrorCode(), "afl-showmap failed");
 
+  }
+
   // Parse afl-showmap output
   const auto CovOrErr = MemoryBuffer::getFile(TracePath);
   if (const auto EC = CovOrErr.getError()) {
@@ -287,6 +292,8 @@ int main(int argc, char *argv[]) {
   SkipBinCheck = !!std::getenv("AFL_SKIP_BIN_CHECK");
   const auto AFLPath = std::getenv("AFL_PATH");
 
+  if (CrashMode) ::setenv("AFL_CMIN_CRASHES_ONLY", "1", /*overwrite=*/true);
+
   for (const auto &Arg : TargetArgs)
     if (Arg == "@@") TargetArgsHasAtAt = true;
 
@@ -354,8 +361,8 @@ int main(int argc, char *argv[]) {
 
   if ((EC = sys::fs::create_directories(TraceDir))) {
 
-    ErrMsg() << "Failed to create output directory `" << OutputDir << "`: "
-             << EC.message() << '\n';
+    ErrMsg() << "Failed to create output directory `" << OutputDir
+             << "`: " << EC.message() << '\n';
     return 1;
 
   }
@@ -421,7 +428,8 @@ int main(int argc, char *argv[]) {
 
     if (auto Err = getAFLCoverage(SeedFiles.front(), Cov, /*BinCheck=*/true)) {
 
-      ErrMsg() << "No instrumentation output detected (perhaps crash or timeout)";
+      ErrMsg()
+          << "No instrumentation output detected (perhaps crash or timeout)";
       return 1;
 
     }
@@ -456,8 +464,8 @@ int main(int argc, char *argv[]) {
     Cov.clear();
     if (auto Err = getAFLCoverage(SeedFile, Cov)) {
 
-      ErrMsg() << "Failed to get coverage for seed `" << SeedFile << "`: "
-               << Err << '\n';
+      ErrMsg() << "Failed to get coverage for seed `" << SeedFile
+               << "`: " << Err << '\n';
       return 1;
 
     }