forked from OSchip/llvm-project
[libFuzzer] Properly handle exceptions with UnhandledExceptionFilter.
Use SetUnhandledExceptionFilter instead of AddVectoredExceptionHandler. According to the documentation on Structured Exception Handling, this is the order for the Exception Dispatching: + If the process is being debugged, the system notifies the debugger. + The Vectored Exception Handler is called. + The system attempts to locate a frame-based exception handler by searching the stack frames of the thread in which the exception occurred. + If no frame-based handler can be found, the UnhandledExceptionFilter filter is called. + Default handling based on the exception type. So, similar to what we do for asan, we should use SetUnhandledExceptionFilter instead of AddVectoredExceptionHandler, so user's code that is being fuzzed can execute frame-based exception handlers before we catch them . We want to catch unhandled exceptions, not all the exceptions. Differential Revision: https://reviews.llvm.org/D29462 llvm-svn: 293920
This commit is contained in:
parent
37e2459186
commit
d64360d935
|
@ -28,7 +28,7 @@ namespace fuzzer {
|
||||||
|
|
||||||
static const FuzzingOptions* HandlerOpt = nullptr;
|
static const FuzzingOptions* HandlerOpt = nullptr;
|
||||||
|
|
||||||
LONG CALLBACK ExceptionHandler(PEXCEPTION_POINTERS ExceptionInfo) {
|
static LONG CALLBACK ExceptionHandler(PEXCEPTION_POINTERS ExceptionInfo) {
|
||||||
switch (ExceptionInfo->ExceptionRecord->ExceptionCode) {
|
switch (ExceptionInfo->ExceptionRecord->ExceptionCode) {
|
||||||
case EXCEPTION_ACCESS_VIOLATION:
|
case EXCEPTION_ACCESS_VIOLATION:
|
||||||
case EXCEPTION_ARRAY_BOUNDS_EXCEEDED:
|
case EXCEPTION_ARRAY_BOUNDS_EXCEEDED:
|
||||||
|
@ -126,10 +126,7 @@ void SetSignalHandler(const FuzzingOptions& Options) {
|
||||||
|
|
||||||
if (Options.HandleSegv || Options.HandleBus || Options.HandleIll ||
|
if (Options.HandleSegv || Options.HandleBus || Options.HandleIll ||
|
||||||
Options.HandleFpe)
|
Options.HandleFpe)
|
||||||
if (!AddVectoredExceptionHandler(1, ExceptionHandler)) {
|
SetUnhandledExceptionFilter(ExceptionHandler);
|
||||||
Printf("libFuzzer: AddVectoredExceptionHandler failed.\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Options.HandleAbrt)
|
if (Options.HandleAbrt)
|
||||||
if (SIG_ERR == signal(SIGABRT, CrashHandler)) {
|
if (SIG_ERR == signal(SIGABRT, CrashHandler)) {
|
||||||
|
|
Loading…
Reference in New Issue