Skip to content

Commit f666d98

Browse files
committed
driver: Fix timeouts not being detected anymore
Since switching to libFuzzer-in-JVM, its timeout detection was broken since the alarm callback ran on another thread and thus skipped its logic. This is fixed by patching out the thread check.
1 parent 6e904dd commit f666d98

4 files changed

Lines changed: 60 additions & 9 deletions

File tree

bazel/tools/java/com/code_intelligence/jazzer/tools/FuzzTargetTestWrapper.java

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,10 @@ public static void main(String[] args) {
153153
}
154154
System.exit(0);
155155
}
156-
// Assert that we either found a crash in Java (exit code 77) or a sanitizer crash (exit code
157-
// 76).
158-
if (exitCode != 76 && exitCode != 77) {
156+
// Assert that we either found a crash in Java (exit code 77), a sanitizer crash (exit code
157+
// 76), or a timeout (exit code 70).
158+
if (exitCode != 76 && exitCode != 77
159+
&& !(allowedFindings.contains("timeout") && exitCode == 70)) {
159160
System.err.printf("Did expect a crash, but Jazzer exited with exit code %d%n", exitCode);
160161
System.exit(1);
161162
}
@@ -167,7 +168,10 @@ public static void main(String[] args) {
167168
// Verify that libFuzzer dumped a crashing input.
168169
if (JAZZER_CI && shouldVerifyCrashInput
169170
&& outputFiles.stream().noneMatch(
170-
name -> name.getFileName().toString().startsWith("crash-"))) {
171+
name -> name.getFileName().toString().startsWith("crash-"))
172+
&& !(allowedFindings.contains("timeout")
173+
&& outputFiles.stream().anyMatch(
174+
name -> name.getFileName().toString().startsWith("timeout-")))) {
171175
System.err.printf("No crashing input found in %s%n", outputDir);
172176
System.exit(1);
173177
}
@@ -222,9 +226,20 @@ private static void verifyFuzzerOutput(
222226
throw new IllegalStateException(
223227
"Expected stack traces for all threads, but did not get any");
224228
}
225-
if (expectedFindings.size() == 1) {
226-
return;
229+
if (expectedFindings.size() != 1) {
230+
throw new IllegalStateException("Cannot expect both a native and other findings");
227231
}
232+
return;
233+
}
234+
if (expectedFindings.contains("timeout")) {
235+
if (!stackTrace.contains(THREAD_DUMP_HEADER) || stackTrace.size() < 3) {
236+
throw new IllegalStateException(
237+
"Expected stack traces for all threads, but did not get any");
238+
}
239+
if (expectedFindings.size() != 1) {
240+
throw new IllegalStateException("Cannot expect both a timeout and other findings");
241+
}
242+
return;
228243
}
229244
List<String> findings =
230245
stackTrace.stream()

repositories.bzl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def jazzer_dependencies():
132132
http_archive,
133133
name = "jazzer_libfuzzer",
134134
build_file = Label("//third_party:libFuzzer.BUILD"),
135-
sha256 = "4dad21b6a07571c851b8b67cc8ad9172a3fee49ba10f7de03368796ae9494813",
136-
strip_prefix = "llvm-project-jazzer-2022-09-09/compiler-rt/lib/fuzzer",
137-
url = "https://github.com/CodeIntelligenceTesting/llvm-project-jazzer/archive/refs/tags/2022-09-09.tar.gz",
135+
sha256 = "cfb91ee60ff03cec204e387f4af4fd4f031eb1257fd6481aa69ac748deecd1d1",
136+
strip_prefix = "llvm-project-jazzer-2022-12-07/compiler-rt/lib/fuzzer",
137+
url = "https://github.com/CodeIntelligenceTesting/llvm-project-jazzer/archive/refs/tags/2022-12-07.tar.gz",
138138
)

tests/BUILD.bazel

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,3 +334,15 @@ java_fuzz_target_test(
334334
target_class = "com.example.KotlinVarargFuzzer",
335335
deps = [":kotlin_vararg"],
336336
)
337+
338+
java_fuzz_target_test(
339+
name = "TimeoutFuzzer",
340+
timeout = "short",
341+
srcs = ["src/test/java/com/example/TimeoutFuzzer.java"],
342+
allowed_findings = ["timeout"],
343+
fuzzer_args = [
344+
"-timeout=1",
345+
],
346+
target_class = "com.example.TimeoutFuzzer",
347+
verify_crash_reproducer = False,
348+
)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright 2022 Code Intelligence GmbH
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example;
18+
19+
public class TimeoutFuzzer {
20+
public static void fuzzerTestOneInput(byte[] b) {
21+
while (true) {
22+
}
23+
}
24+
}

0 commit comments

Comments
 (0)