[compiler-rt] aa0e904 - Libfuzzer fix for Ctrl + c not working with -fork and -ignore_crashes=1

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 16 16:45:48 PDT 2022


Author: Maxim Schessler
Date: 2022-08-16T16:45:39-07:00
New Revision: aa0e9046c16bf27a8affbd903e2e3cad924a5217

URL: https://github.com/llvm/llvm-project/commit/aa0e9046c16bf27a8affbd903e2e3cad924a5217
DIFF: https://github.com/llvm/llvm-project/commit/aa0e9046c16bf27a8affbd903e2e3cad924a5217.diff

LOG: Libfuzzer fix for Ctrl + c not working with -fork and -ignore_crashes=1

In some cases running Libfuzzer in fork mode with -ignore_crashes=1 counts ctrl+c as crash and restarts.

Thread: https://github.com/google/oss-fuzz/issues/4547

Credit: Marcel Boehme <marcel.boehme at acm.org>

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D130990

Added: 
    

Modified: 
    compiler-rt/lib/fuzzer/FuzzerInternal.h
    compiler-rt/lib/fuzzer/FuzzerLoop.cpp
    compiler-rt/lib/fuzzer/FuzzerUtilLinux.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/fuzzer/FuzzerInternal.h b/compiler-rt/lib/fuzzer/FuzzerInternal.h
index 31f54eaa478a8..a732ca87b0f31 100644
--- a/compiler-rt/lib/fuzzer/FuzzerInternal.h
+++ b/compiler-rt/lib/fuzzer/FuzzerInternal.h
@@ -91,6 +91,7 @@ class Fuzzer {
 
   void HandleMalloc(size_t Size);
   static void MaybeExitGracefully();
+  static int InterruptExitCode();
   std::string WriteToOutputCorpus(const Unit &U);
 
 private:

diff  --git a/compiler-rt/lib/fuzzer/FuzzerLoop.cpp b/compiler-rt/lib/fuzzer/FuzzerLoop.cpp
index f095757229e9e..00f5ed7743b61 100644
--- a/compiler-rt/lib/fuzzer/FuzzerLoop.cpp
+++ b/compiler-rt/lib/fuzzer/FuzzerLoop.cpp
@@ -262,6 +262,11 @@ void Fuzzer::MaybeExitGracefully() {
   _Exit(0);
 }
 
+int Fuzzer::InterruptExitCode() {
+  assert(F);
+  return F->Options.InterruptExitCode;
+}
+
 void Fuzzer::InterruptCallback() {
   Printf("==%lu== libFuzzer: run interrupted; exiting\n", GetPid());
   PrintFinalStats();

diff  --git a/compiler-rt/lib/fuzzer/FuzzerUtilLinux.cpp b/compiler-rt/lib/fuzzer/FuzzerUtilLinux.cpp
index 981f9a8b429f7..7e22f0e9fe8f2 100644
--- a/compiler-rt/lib/fuzzer/FuzzerUtilLinux.cpp
+++ b/compiler-rt/lib/fuzzer/FuzzerUtilLinux.cpp
@@ -11,6 +11,7 @@
 #if LIBFUZZER_LINUX || LIBFUZZER_NETBSD || LIBFUZZER_FREEBSD ||                \
     LIBFUZZER_EMSCRIPTEN
 #include "FuzzerCommand.h"
+#include "FuzzerInternal.h"
 
 #include <stdlib.h>
 #include <sys/types.h>
@@ -25,6 +26,8 @@ int ExecuteCommand(const Command &Cmd) {
   int exit_code = system(CmdLine.c_str());
   if (WIFEXITED(exit_code))
     return WEXITSTATUS(exit_code);
+  if (WIFSIGNALED(exit_code) && WTERMSIG(exit_code) == SIGINT)
+    return Fuzzer::InterruptExitCode();
   return exit_code;
 }
 


        


More information about the llvm-commits mailing list