From 32e6c84d10e439d4cee3380e44c904bf48230983 Mon Sep 17 00:00:00 2001 From: Norbert Schneider Date: Thu, 6 Apr 2023 16:17:15 +0200 Subject: [PATCH] autofuzz: Fix logs for bug detector findings Autofuzz tries to print caught exceptions, but this fails in case of bug detector findings, as the thrown exceptions are intentionally hard to catch and rethrow themselves if possible. Due to this behavior the following line is potentially loged multiple times: `ERROR: Unexpected exception encountered during autofuzz:` In this case the exceptions are also only used to abort the current invocation, logging of the actual findings is done by different means. So it's save to ignore this kind of exceptions. --- .../jazzer/api/AutofuzzInvocationException.java | 4 ++++ .../java/com/code_intelligence/jazzer/autofuzz/BUILD.bazel | 1 + .../java/com/code_intelligence/jazzer/autofuzz/Meta.java | 7 +++++++ .../java/com/code_intelligence/jazzer/runtime/BUILD.bazel | 1 + 4 files changed, 13 insertions(+) diff --git a/src/main/java/com/code_intelligence/jazzer/api/AutofuzzInvocationException.java b/src/main/java/com/code_intelligence/jazzer/api/AutofuzzInvocationException.java index 7e6203cea..eb936630e 100644 --- a/src/main/java/com/code_intelligence/jazzer/api/AutofuzzInvocationException.java +++ b/src/main/java/com/code_intelligence/jazzer/api/AutofuzzInvocationException.java @@ -20,6 +20,10 @@ * Only used internally. */ public class AutofuzzInvocationException extends RuntimeException { + public AutofuzzInvocationException() { + super(); + } + public AutofuzzInvocationException(Throwable cause) { super(cause); } diff --git a/src/main/java/com/code_intelligence/jazzer/autofuzz/BUILD.bazel b/src/main/java/com/code_intelligence/jazzer/autofuzz/BUILD.bazel index 1b8e8124f..04a076e69 100644 --- a/src/main/java/com/code_intelligence/jazzer/autofuzz/BUILD.bazel +++ b/src/main/java/com/code_intelligence/jazzer/autofuzz/BUILD.bazel @@ -11,6 +11,7 @@ java_library( visibility = ["//visibility:public"], deps = [ "//src/main/java/com/code_intelligence/jazzer/api", + "//src/main/java/com/code_intelligence/jazzer/runtime:jazzer_bootstrap_compile_only", "//src/main/java/com/code_intelligence/jazzer/utils", "//src/main/java/com/code_intelligence/jazzer/utils:log", "//src/main/java/com/code_intelligence/jazzer/utils:simple_glob_matcher", diff --git a/src/main/java/com/code_intelligence/jazzer/autofuzz/Meta.java b/src/main/java/com/code_intelligence/jazzer/autofuzz/Meta.java index 8df556d72..543284f14 100644 --- a/src/main/java/com/code_intelligence/jazzer/autofuzz/Meta.java +++ b/src/main/java/com/code_intelligence/jazzer/autofuzz/Meta.java @@ -27,6 +27,7 @@ import com.code_intelligence.jazzer.api.Function4; import com.code_intelligence.jazzer.api.Function5; import com.code_intelligence.jazzer.api.FuzzedDataProvider; +import com.code_intelligence.jazzer.runtime.HardToCatchError; import com.code_intelligence.jazzer.utils.Utils; import io.github.classgraph.ClassGraph; import io.github.classgraph.ClassInfoList; @@ -286,6 +287,9 @@ Object autofuzz( // We should ensure that the arguments fed into the method are always valid. throw new AutofuzzError(getDebugSummary(method, thisObject, arguments), e); } catch (InvocationTargetException e) { + if (e.getCause() instanceof HardToCatchError) { + throw new AutofuzzInvocationException(); + } throw new AutofuzzInvocationException(e.getCause()); } } @@ -344,6 +348,9 @@ R autofuzz( // constructors of abstract classes or private constructors. throw new AutofuzzError(getDebugSummary(constructor, null, arguments), e); } catch (InvocationTargetException e) { + if (e.getCause() instanceof HardToCatchError) { + throw new AutofuzzInvocationException(); + } throw new AutofuzzInvocationException(e.getCause()); } } diff --git a/src/main/java/com/code_intelligence/jazzer/runtime/BUILD.bazel b/src/main/java/com/code_intelligence/jazzer/runtime/BUILD.bazel index 95a64d4cc..59064a85a 100644 --- a/src/main/java/com/code_intelligence/jazzer/runtime/BUILD.bazel +++ b/src/main/java/com/code_intelligence/jazzer/runtime/BUILD.bazel @@ -83,6 +83,7 @@ java_library( name = "jazzer_bootstrap_compile_only", neverlink = True, visibility = [ + "//src/main/java/com/code_intelligence/jazzer/autofuzz:__pkg__", "//src/main/java/com/code_intelligence/jazzer/driver:__pkg__", "//src/main/java/com/code_intelligence/jazzer/instrumentor:__pkg__", ],