Skip to content

Commit 3eaaa73

Browse files
Add tests for trace-pc-guard instrumentation (aflnet#26)
Also fix copied test and remove trailing whitespace.
1 parent c45fd01 commit 3eaaa73

File tree

2 files changed

+59
-11
lines changed

2 files changed

+59
-11
lines changed

.travis.yml

+18-11
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ language: c
22

33
env:
44
- AFL_I_DONT_CARE_ABOUT_MISSING_CRASHES=1 AFL_NO_UI=1 AFL_STOP_MANUALLY=1
5-
- AFL_I_DONT_CARE_ABOUT_MISSING_CRASHES=1 AFL_NO_UI=1 AFL_EXIT_WHEN_DONE=1
5+
- AFL_I_DONT_CARE_ABOUT_MISSING_CRASHES=1 AFL_NO_UI=1 AFL_EXIT_WHEN_DONE=1
66
# TODO: test AFL_BENCH_UNTIL_CRASH once we have a target that crashes
77
- AFL_I_DONT_CARE_ABOUT_MISSING_CRASHES=1 AFL_NO_UI=1 AFL_BENCH_JUST_ONE=1
88

@@ -11,43 +11,50 @@ before_install:
1111
- sudo apt install -y libtool libtool-bin automake bison libglib2.0
1212

1313
# TODO: Look into splitting off some builds using a build matrix.
14+
# TODO: Move this all into a bash script so we don't need to write bash in yaml.
1415
script:
1516
- make
1617
- ./afl-gcc ./test-instr.c -o test-instr-gcc
1718
- mkdir seeds
1819
- echo "" > seeds/nil_seed
19-
- if [ -z "$AFL_STOP_MANUALLY" ];
20-
then ./afl-fuzz -i seeds -o out/ -- ./test-instr-gcc;
20+
- if [ -z "$AFL_STOP_MANUALLY" ];
21+
then ./afl-fuzz -i seeds -o out/ -- ./test-instr-gcc;
2122
else timeout --preserve-status 5s ./afl-fuzz -i seeds -o out/ -- ./test-instr-gcc;
2223
fi
2324
- .travis/check_fuzzer_stats.sh -o out -k peak_rss_mb -v 1 -p 3
2425
- rm -r out/*
2526
- ./afl-clang ./test-instr.c -o test-instr-clang
26-
- if [ -z "$AFL_STOP_MANUALLY" ];
27-
then ./afl-fuzz -i seeds -o out/ -- ./test-instr-clang;
27+
- if [ -z "$AFL_STOP_MANUALLY" ];
28+
then ./afl-fuzz -i seeds -o out/ -- ./test-instr-clang;
2829
else timeout --preserve-status 5s ./afl-fuzz -i seeds -o out/ -- ./test-instr-clang;
2930
fi
3031
- .travis/check_fuzzer_stats.sh -o out -k peak_rss_mb -v 1 -p 2
3132
- make clean
3233
- CC=clang CXX=clang++ make
3334
- cd llvm_mode
34-
# TODO: Build with different versions of clang/LLVM since LLVM passes don't have
35-
# a stable API.
35+
# TODO: Build with different versions of clang/LLVM since LLVM passes don't
36+
# have a stable API.
3637
- CC=clang CXX=clang++ LLVM_CONFIG=llvm-config make
3738
- cd ..
3839
- rm -r out/*
3940
- ./afl-clang-fast ./test-instr.c -o test-instr-clang-fast
40-
- if [ -z "$AFL_STOP_MANUALLY" ];
41-
then ./afl-fuzz -i seeds -o out/ -- ./test-instr-clang;
41+
- if [ -z "$AFL_STOP_MANUALLY" ];
42+
then ./afl-fuzz -i seeds -o out/ -- ./test-instr-clang-fast;
4243
else timeout --preserve-status 5s ./afl-fuzz -i seeds -o out/ -- ./test-instr-clang-fast;
4344
fi
4445
- .travis/check_fuzzer_stats.sh -o out -k peak_rss_mb -v 1 -p 3
46+
# Test fuzzing libFuzzer targets and trace-pc-guard instrumentation.
47+
- clang -g -fsanitize-coverage=trace-pc-guard ./test-libfuzzer-target.c -c
48+
- clang -c -w llvm_mode/afl-llvm-rt.o.c
49+
- wget https://raw.githubusercontent.com/llvm/llvm-project/master/compiler-rt/lib/fuzzer/afl/afl_driver.cpp
50+
- clang++ afl_driver.cpp afl-llvm-rt.o.o test-libfuzzer-target.o -o test-libfuzzer-target
51+
- timeout --preserve-status 5s ./afl-fuzz -i seeds -o out/ -- ./test-libfuzzer-target
4552
- cd qemu_mode
4653
- ./build_qemu_support.sh
4754
- cd ..
4855
- gcc ./test-instr.c -o test-no-instr
49-
- if [ -z "$AFL_STOP_MANUALLY" ];
50-
then ./afl-fuzz -Q -i seeds -o out/ -- ./test-no-instr;
56+
- if [ -z "$AFL_STOP_MANUALLY" ];
57+
then ./afl-fuzz -Q -i seeds -o out/ -- ./test-no-instr;
5158
else timeout --preserve-status 5s ./afl-fuzz -Q -i seeds -o out/ -- ./test-no-instr;
5259
fi
5360
- .travis/check_fuzzer_stats.sh -o out -k peak_rss_mb -v 12 -p 9

test-libfuzzer-target.c

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
Copyright 2019 Google LLC All rights reserved.
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+
18+
/*
19+
american fuzzy lop - a trivial program to test libFuzzer target fuzzing.
20+
------------------------------------------------------------------------
21+
22+
Initially written and maintained by Michal Zalewski.
23+
*/
24+
25+
#include <stddef.h>
26+
#include <stdint.h>
27+
#include <stdio.h>
28+
29+
// TODO(metzman): Create a test/ directory to store this and other similar
30+
// files.
31+
int LLVMFuzzerTestOneInput(uint8_t* buf, size_t size) {
32+
if (size < 2)
33+
return 0;
34+
35+
if (buf[0] == '0')
36+
printf("Looks like a zero to me!\n");
37+
else
38+
printf("A non-zero value? How quaint!\n");
39+
40+
return 0;
41+
}

0 commit comments

Comments
 (0)