Skip to content

Commit 9a01527

Browse files
committed
[compiler-rt] fuzzer: adjust tests to not expect that store to null traps and is not erase
Instead, mostly just trap directly.
1 parent 3f7c9cc commit 9a01527

File tree

10 files changed

+27
-31
lines changed

10 files changed

+27
-31
lines changed

compiler-rt/test/fuzzer/ShallowOOMDeepCrash.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
1616
Sink = new int[1 << 28]; // instant OOM with -rss_limit_mb=128.
1717
if (Size >= 4 && Data[0] == 'F' && Data[1] == 'U' && Data[2] == 'Z' &&
1818
Data[3] == 'Z') // a bit deeper crash.
19-
*Zero = 42;
19+
__builtin_trap();
2020
return 0;
2121
}
2222

compiler-rt/test/fuzzer/NullDerefTest.cpp renamed to compiler-rt/test/fuzzer/TrapTest.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,21 @@
55
// Simple test for a fuzzer. The fuzzer must find the string "Hi!".
66
#include <cstddef>
77
#include <cstdint>
8-
#include <cstdlib>
98
#include <cstdio>
9+
#include <cstdlib>
1010

1111
static volatile int Sink;
12-
static volatile int *Null = 0;
1312

1413
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
1514
if (Size > 0 && Data[0] == 'H') {
1615
Sink = 1;
1716
if (Size > 1 && Data[1] == 'i') {
1817
Sink = 2;
1918
if (Size > 2 && Data[2] == '!') {
20-
printf("Found the target, dereferencing NULL\n");
21-
*Null = 1;
19+
printf("Found the target, trapping\n");
20+
__builtin_trap();
2221
}
2322
}
2423
}
2524
return 0;
2625
}
27-

compiler-rt/test/fuzzer/coverage.test

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
UNSUPPORTED: windows
33
# FIXME: CreatePCArray() emits PLT stub addresses for entry blocks, which are ignored by TracePC::PrintCoverage().
44
XFAIL: s390x
5-
RUN: %cpp_compiler -mllvm -use-unknown-locations=Disable %S/NullDerefTest.cpp -o %t-NullDerefTest
5+
RUN: %cpp_compiler -mllvm -use-unknown-locations=Disable %S/TrapTest.cpp -o %t-TrapTest
66
RUN: %cpp_compiler -mllvm -use-unknown-locations=Disable %S/DSO1.cpp -fPIC %ld_flags_rpath_so1 -O0 -shared -o %dynamiclib1
77
RUN: %cpp_compiler -mllvm -use-unknown-locations=Disable %S/DSO2.cpp -fPIC %ld_flags_rpath_so2 -O0 -shared -o %dynamiclib2
88
RUN: %cpp_compiler -mllvm -use-unknown-locations=Disable %S/DSOTestMain.cpp %S/DSOTestExtra.cpp %ld_flags_rpath_exe1 %ld_flags_rpath_exe2 -o %t-DSOTest
99

1010
CHECK: COVERAGE:
11-
CHECK: COVERED_FUNC: {{.*}}LLVMFuzzerTestOneInput {{.*}}NullDerefTest.cpp:14
12-
RUN: not %run %t-NullDerefTest -print_coverage=1 2>&1 | FileCheck %s
11+
CHECK: COVERED_FUNC: {{.*}}LLVMFuzzerTestOneInput {{.*}}TrapTest.cpp:13
12+
RUN: not %run %t-TrapTest -print_coverage=1 2>&1 | FileCheck %s
1313

1414
RUN: %run %t-DSOTest -print_coverage=1 -runs=0 2>&1 | FileCheck %s --check-prefix=DSO
1515
DSO: COVERAGE:

compiler-rt/test/fuzzer/fork.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ RUN: %cpp_compiler %S/OutOfMemoryTest.cpp -o %t-OutOfMemoryTest
1212
RUN: not %run %t-OutOfMemoryTest -fork=1 -ignore_ooms=0 -rss_limit_mb=128 2>&1 | FileCheck %s --check-prefix=OOM
1313

1414
# access-violation is the error thrown on Windows. Address will be smaller on i386.
15-
CRASH: {{SEGV|access-violation}} on unknown address 0x00000000
15+
CRASH: == ERROR: libFuzzer: deadly signal
1616
RUN: %cpp_compiler %S/ShallowOOMDeepCrash.cpp -o %t-ShallowOOMDeepCrash
1717
RUN: not %run %t-ShallowOOMDeepCrash -fork=1 -rss_limit_mb=128 2>&1 | FileCheck %s --check-prefix=CRASH
1818

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
RUN: %cpp_compiler %S/NullDerefTest.cpp -o %t-SimpleCmpTest
1+
RUN: %cpp_compiler %S/TrapTest.cpp -o %t-SimpleCmpTest
22
RUN: %run %t-SimpleCmpTest -seed=-1 -runs=0 2>&1 | FileCheck %s --check-prefix=CHECK_SEED_MINUS_ONE
33
CHECK_SEED_MINUS_ONE: Seed: 4294967295
44

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
RUN: %cpp_compiler %S/NullDerefTest.cpp -o %t-NullDerefTest
2-
RUN: %env_asan_opts=handle_segv=0 not %run %t-NullDerefTest 2>&1 | FileCheck %s --check-prefix=LIBFUZZER_OWN_SEGV_HANDLER
1+
RUN: %cpp_compiler %S/TrapTest.cpp -o %t-TrapTest
2+
RUN: %env_asan_opts=handle_segv=0 not %run %t-TrapTest 2>&1 | FileCheck %s --check-prefix=LIBFUZZER_OWN_SEGV_HANDLER
3+
RUN: %env_asan_opts=handle_segv=1 not %run %t-TrapTest 2>&1 | FileCheck %s --check-prefix=LIBFUZZER_OWN_SEGV_HANDLER
34
LIBFUZZER_OWN_SEGV_HANDLER: == ERROR: libFuzzer: deadly signal
45
LIBFUZZER_OWN_SEGV_HANDLER: SUMMARY: libFuzzer: deadly signal
56
LIBFUZZER_OWN_SEGV_HANDLER: Test unit written to ./crash-
6-
7-
RUN: %env_asan_opts=handle_segv=1 not %run %t-NullDerefTest 2>&1 | FileCheck %s --check-prefix=LIBFUZZER_ASAN_SEGV_HANDLER
8-
LIBFUZZER_ASAN_SEGV_HANDLER: ERROR: AddressSanitizer: {{SEGV|access-violation}} on unknown address

compiler-rt/test/fuzzer/fuzzer-singleinputs.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
RUN: %cpp_compiler %S/NullDerefTest.cpp -o %t-NullDerefTest
1+
RUN: %cpp_compiler %S/TrapTest.cpp -o %t-TrapTest
22
RUN: %cpp_compiler %S/SimpleTest.cpp -o %t-SimpleTest
33

4-
RUN: not %run %t-NullDerefTest %S/hi.txt 2>&1 | FileCheck %s --check-prefix=SingleInput
4+
RUN: not %run %t-TrapTest %S/hi.txt 2>&1 | FileCheck %s --check-prefix=SingleInput
55
SingleInput-NOT: Test unit written to ./crash-
66

77
RUN: rm -rf %tmp/SINGLE_INPUTS

compiler-rt/test/fuzzer/minimize_crash.test

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
RUN: %cpp_compiler %S/NullDerefTest.cpp -o %t-NullDerefTest
1+
RUN: %cpp_compiler %S/TrapTest.cpp -o %t-TrapTest
22
RUN: %cpp_compiler %S/SingleByteInputTest.cpp -o %t-SingleByteInputTest
33
RUN: mkdir -p %t.dir
44

55
RUN: echo 'Hi!rv349f34t3gg' > %t.dir/not_minimal_crash
6-
RUN: %run %t-NullDerefTest -minimize_crash=1 %t.dir/not_minimal_crash -max_total_time=2 2>&1 | FileCheck %s
6+
RUN: %run %t-TrapTest -minimize_crash=1 %t.dir/not_minimal_crash -max_total_time=2 2>&1 | FileCheck %s
77
CHECK: CRASH_MIN: failed to minimize beyond {{.*}}minimized-from{{.*}} (3 bytes), exiting
8-
RUN: %run %t-NullDerefTest -minimize_crash=1 %t.dir/not_minimal_crash -max_total_time=2 -exact_artifact_path=%t.exact_minimized_path 2>&1 | FileCheck %s --check-prefix=CHECK_EXACT
8+
RUN: %run %t-TrapTest -minimize_crash=1 %t.dir/not_minimal_crash -max_total_time=2 -exact_artifact_path=%t.exact_minimized_path 2>&1 | FileCheck %s --check-prefix=CHECK_EXACT
99
CHECK_EXACT: CRASH_MIN: failed to minimize beyond {{.*}}exact_minimized_path{{.*}} (3 bytes), exiting
1010
RUN: rm %t.dir/not_minimal_crash %t.exact_minimized_path
1111

compiler-rt/test/fuzzer/null-deref.test

Lines changed: 0 additions & 10 deletions
This file was deleted.

compiler-rt/test/fuzzer/trap.test

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
RUN: %cpp_compiler %S/TrapTest.cpp -o %t-TrapTest
2+
3+
RUN: not %run %t-TrapTest 2>&1 | FileCheck %s --check-prefix=TrapTest
4+
RUN: not %run %t-TrapTest -close_fd_mask=3 2>&1 | FileCheck %s --check-prefix=TrapTest
5+
TrapTest: SUMMARY: libFuzzer: deadly signal
6+
TrapTest: Test unit written to ./crash-
7+
RUN: not %run %t-TrapTest -artifact_prefix=ZZZ 2>&1 | FileCheck %s --check-prefix=TrapTestPrefix
8+
TrapTestPrefix: Test unit written to ZZZcrash-
9+
RUN: not %run %t-TrapTest -artifact_prefix=ZZZ -exact_artifact_path=FOOBAR 2>&1 | FileCheck %s --check-prefix=TrapTestExactPath
10+
TrapTestExactPath: Test unit written to FOOBAR

0 commit comments

Comments
 (0)