Index: llvm/trunk/lib/Fuzzer/FuzzerUtilPosix.cpp =================================================================== --- llvm/trunk/lib/Fuzzer/FuzzerUtilPosix.cpp +++ llvm/trunk/lib/Fuzzer/FuzzerUtilPosix.cpp @@ -47,8 +47,21 @@ static void SetSigaction(int signum, void (*callback)(int, siginfo_t *, void *)) { - struct sigaction sigact; - memset(&sigact, 0, sizeof(sigact)); + struct sigaction sigact = {}; + if (sigaction(signum, nullptr, &sigact)) { + Printf("libFuzzer: sigaction failed with %d\n", errno); + exit(1); + } + if (sigact.sa_flags & SA_SIGINFO) { + if (sigact.sa_sigaction) + return; + } else { + if (sigact.sa_handler != SIG_DFL && sigact.sa_handler != SIG_IGN && + sigact.sa_handler != SIG_ERR) + return; + } + + sigact = {}; sigact.sa_sigaction = callback; if (sigaction(signum, &sigact, 0)) { Printf("libFuzzer: sigaction failed with %d\n", errno); Index: llvm/trunk/lib/Fuzzer/test/fuzzer-segv.test =================================================================== --- llvm/trunk/lib/Fuzzer/test/fuzzer-segv.test +++ llvm/trunk/lib/Fuzzer/test/fuzzer-segv.test @@ -3,3 +3,5 @@ LIBFUZZER_OWN_SEGV_HANDLER: SUMMARY: libFuzzer: deadly signal LIBFUZZER_OWN_SEGV_HANDLER: Test unit written to ./crash- +RUN: env ASAN_OPTIONS=handle_segv=1 not LLVMFuzzer-NullDerefTest 2>&1 | FileCheck %s --check-prefix=LIBFUZZER_ASAN_SEGV_HANDLER +LIBFUZZER_ASAN_SEGV_HANDLER: ERROR: AddressSanitizer: {{SEGV|access-violation}} on unknown address