[llvm] r271053 - [libFuzzer] use __sanitizer_set_report_fd with -close_fd_mask. This allows us to keep asan reports when closing target's stderr
Kostya Serebryany via llvm-commits
llvm-commits at lists.llvm.org
Fri May 27 14:46:22 PDT 2016
Author: kcc
Date: Fri May 27 16:46:22 2016
New Revision: 271053
URL: http://llvm.org/viewvc/llvm-project?rev=271053&view=rev
Log:
[libFuzzer] use __sanitizer_set_report_fd with -close_fd_mask. This allows us to keep asan reports when closing target's stderr
Modified:
llvm/trunk/docs/LibFuzzer.rst
llvm/trunk/lib/Fuzzer/FuzzerIO.cpp
llvm/trunk/lib/Fuzzer/test/fuzzer.test
Modified: llvm/trunk/docs/LibFuzzer.rst
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/LibFuzzer.rst?rev=271053&r1=271052&r2=271053&view=diff
==============================================================================
--- llvm/trunk/docs/LibFuzzer.rst (original)
+++ llvm/trunk/docs/LibFuzzer.rst Fri May 27 16:46:22 2016
@@ -273,9 +273,8 @@ The most important command line options
If 1 (default) and if LeakSanitizer is enabled
try to detect memory leaks during fuzzing (i.e. not only at shut down).
``-close_fd_mask``
- Indicate output streams to close at startup. Be careful, this will also
- remove diagnostic output from the tools in use; for example the messages
- AddressSanitizer_ sends to ``stderr``/``stdout`` will also be lost.
+ Indicate output streams to close at startup. Be careful, this will
+ remove diagnostic output from target code (e.g. messages on assert failure).
- 0 (default): close neither ``stdout`` nor ``stderr``
- 1 : close ``stdout``
Modified: llvm/trunk/lib/Fuzzer/FuzzerIO.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerIO.cpp?rev=271053&r1=271052&r2=271053&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerIO.cpp (original)
+++ llvm/trunk/lib/Fuzzer/FuzzerIO.cpp Fri May 27 16:46:22 2016
@@ -18,6 +18,10 @@
#include <cstdarg>
#include <cstdio>
+extern "C" {
+__attribute__((weak)) void __sanitizer_set_report_fd(void *);
+}
+
namespace fuzzer {
static FILE *OutputFile = stderr;
@@ -122,6 +126,8 @@ void DupAndCloseStderr() {
FILE *NewOutputFile = fdopen(OutputFd, "w");
if (NewOutputFile) {
OutputFile = NewOutputFile;
+ if (__sanitizer_set_report_fd)
+ __sanitizer_set_report_fd(reinterpret_cast<void*>(OutputFd));
close(2);
}
}
Modified: llvm/trunk/lib/Fuzzer/test/fuzzer.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/test/fuzzer.test?rev=271053&r1=271052&r2=271053&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/test/fuzzer.test (original)
+++ llvm/trunk/lib/Fuzzer/test/fuzzer.test Fri May 27 16:46:22 2016
@@ -11,7 +11,9 @@ RUN: LLVMFuzzer-SimpleTest -only_ascii=1
RUN: LLVMFuzzer-SimpleCmpTest -max_total_time=1 2>&1 | FileCheck %s --check-prefix=MaxTotalTime
MaxTotalTime: Done {{.*}} runs in {{.}} second(s)
-RUN: not LLVMFuzzer-NullDerefTest 2>&1 | FileCheck %s --check-prefix=NullDerefTest
+RUN: not LLVMFuzzer-NullDerefTest 2>&1 | FileCheck %s --check-prefix=NullDerefTest
+RUN: not LLVMFuzzer-NullDerefTest -close_fd_mask=3 2>&1 | FileCheck %s --check-prefix=NullDerefTest
+NullDerefTest: ERROR: AddressSanitizer: SEGV on unknown address
NullDerefTest: Test unit written to ./crash-
RUN: not LLVMFuzzer-NullDerefTest -artifact_prefix=ZZZ 2>&1 | FileCheck %s --check-prefix=NullDerefTestPrefix
NullDerefTestPrefix: Test unit written to ZZZcrash-
More information about the llvm-commits
mailing list