[PATCH] D33522: [libFuzzer] Don't replace custom signal handlers.
Vitaly Buka via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed May 24 14:45:03 PDT 2017
vitalybuka created this revision.
This allows to keep handlers installed by sanitizers.
In other cases third-party code can replace handlers after libFuzzer
initialization anyway.
https://reviews.llvm.org/D33522
Files:
lib/Fuzzer/FuzzerUtilPosix.cpp
lib/Fuzzer/test/fuzzer-segv.test
Index: lib/Fuzzer/test/fuzzer-segv.test
===================================================================
--- lib/Fuzzer/test/fuzzer-segv.test
+++ 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
Index: lib/Fuzzer/FuzzerUtilPosix.cpp
===================================================================
--- lib/Fuzzer/FuzzerUtilPosix.cpp
+++ lib/Fuzzer/FuzzerUtilPosix.cpp
@@ -47,8 +47,22 @@
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);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33522.100167.patch
Type: text/x-patch
Size: 1475 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170524/328a1d6f/attachment.bin>
More information about the llvm-commits
mailing list