Skip to content

Commit

Permalink
autofuzz: Fix logs for bug detector findings
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bertschneider authored and fmeum committed Apr 6, 2023
1 parent 3969c02 commit 32e6c84
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
* Only used internally.
*/
public class AutofuzzInvocationException extends RuntimeException {
public AutofuzzInvocationException() {
super();
}

public AutofuzzInvocationException(Throwable cause) {
super(cause);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/com/code_intelligence/jazzer/autofuzz/Meta.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
}
Expand Down Expand Up @@ -344,6 +348,9 @@ <R> 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());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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__",
],
Expand Down

0 comments on commit 32e6c84

Please sign in to comment.