-
Notifications
You must be signed in to change notification settings - Fork 457
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add more fuzzers and libFuzzer harness #553
Merged
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
0277ce5
Add LLVM fuzzer harness
1c8ec2e
Add AFL++ test case generator
b89c76b
Fuzz more gridDisk functions
79d2e2c
add fuzzerH3SetToLinkedGeo
a28a807
Add more fuzzers
9445cbb
Additional fuzzers
f971dcf
add fuzzerVertexes
e0c8841
Add test-fuzzer script
007b7c3
Fix linux build
02abb99
Fix fuzzerIndexIO
caedc90
test-fuzzer use subshell for ls
isaacbrodsky de5a2c3
Update test-fuzzer again
isaacbrodsky 8bbc36a
Fix test-fuzzer again
isaacbrodsky 021c994
fuzzerCompact
2195863
Update readme
4a65123
libFuzzer tests
1e7066e
reformat header
0ede718
README updates
65b4ef3
fuzzerDirectedEdge
79b1f44
fuzzerLocalIj
25360ef
fix fuzzerDirectedEdge build
ac4b918
Fix fuzzer programs
isaacbrodsky 1145bce
remove logging
isaacbrodsky cd14266
remove h3Println
isaacbrodsky 76532d8
add fuzzerPoylgonToCells
isaacbrodsky 84bc4e9
Update per review
323d9e9
Merge branch 'master' into llvm-fuzzer-harness
e04c62c
Add comment on memcpy per review
0016f1c
Fix potential crash in vertexRotations
7807131
Merge branch 'master' into llvm-fuzzer-harness
4b4e623
Catch possible failure in getIcosahedronFaces
d501e51
Don't assert specific error in testVertex
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
name: test-fuzzer | ||
|
||
on: | ||
push: | ||
branches: [master, stable-*] | ||
pull_request: | ||
branches: [master, stable-*] | ||
|
||
jobs: | ||
afl-tests: | ||
name: Fuzzer Compilation ${{ matrix.compiler }} | ||
runs-on: ubuntu-latest | ||
env: | ||
CC: ${{ matrix.compiler }} | ||
|
||
strategy: | ||
matrix: | ||
compiler: [clang, gcc] | ||
|
||
steps: | ||
- uses: actions/[email protected] | ||
|
||
- name: Configure build | ||
run: | | ||
mkdir build | ||
cd build | ||
cmake -DCMAKE_BUILD_TYPE=Release .. | ||
|
||
- name: Build | ||
run: | | ||
cd build | ||
make fuzzers | ||
|
||
- name: Run fuzzers once | ||
run: | | ||
cd build | ||
for fuzzer in bin/fuzzer*; do | ||
echo $fuzzer | ||
$fuzzer --generate inputData | ||
$fuzzer inputData | ||
done | ||
|
||
libfuzzer-test: | ||
name: LibFuzzer Compilation ${{ matrix.compiler }} | ||
runs-on: ubuntu-latest | ||
env: | ||
CC: ${{ matrix.compiler }} | ||
|
||
strategy: | ||
matrix: | ||
compiler: [clang] | ||
|
||
steps: | ||
- uses: actions/[email protected] | ||
|
||
- name: Configure build | ||
run: | | ||
mkdir build | ||
cd build | ||
cmake -DCMAKE_BUILD_TYPE=Release -DENABLE_LIBFUZZER=ON .. | ||
|
||
- name: Build | ||
run: | | ||
cd build | ||
make fuzzers | ||
|
||
- name: Run fuzzers once | ||
run: | | ||
cd build | ||
for fuzzer in bin/fuzzer*; do | ||
echo $fuzzer | ||
# TODO: Increase run count | ||
$fuzzer -runs=1000 | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,9 @@ option(BUILD_BENCHMARKS "Build benchmarking applications." ON) | |
option(BUILD_FUZZERS "Build fuzzer applications (for use with afl)." ON) | ||
option(BUILD_FILTERS "Build filter applications." ON) | ||
option(BUILD_GENERATORS "Build code generation applications." ON) | ||
# If ON, libfuzzer settings are used to build the fuzzer harnesses. If OFF, a frontend | ||
# for afl++ is provided instead. | ||
option(ENABLE_LIBFUZZER "Build fuzzers with libFuzzer support." OFF) | ||
|
||
if(WIN32) | ||
# Use bash (usually from Git for Windows) for piping results | ||
|
@@ -89,6 +92,10 @@ if(NOT WIN32) | |
# to fully enable coverage. | ||
list(APPEND H3_LINK_FLAGS $<$<CONFIG:Debug>:--coverage>) | ||
endif() | ||
if(ENABLE_LIBFUZZER) | ||
list(APPEND H3_COMPILE_FLAGS -fsanitize=fuzzer,address,undefined) | ||
list(APPEND H3_LINK_FLAGS -fsanitize=fuzzer,address,undefined) | ||
endif() | ||
Comment on lines
+95
to
+98
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that these settings don't really work for the other binaries since |
||
|
||
option(WARNINGS_AS_ERRORS "Warnings are treated as errors" OFF) | ||
if(WARNINGS_AS_ERRORS) | ||
|
@@ -143,6 +150,7 @@ set(APP_SOURCE_FILES | |
src/apps/applib/include/benchmark.h | ||
src/apps/applib/include/utility.h | ||
src/apps/applib/include/args.h | ||
src/apps/applib/include/aflHarness.h | ||
src/apps/applib/lib/kml.c | ||
src/apps/applib/lib/utility.c | ||
src/apps/applib/lib/args.c) | ||
|
@@ -219,6 +227,19 @@ set(OTHER_SOURCE_FILES | |
src/apps/fuzzers/fuzzerLatLngToCell.c | ||
src/apps/fuzzers/fuzzerCellToLatLng.c | ||
src/apps/fuzzers/fuzzerGridDisk.c | ||
src/apps/fuzzers/fuzzerH3SetToLinkedGeo.c | ||
src/apps/fuzzers/fuzzerDistances.c | ||
src/apps/fuzzers/fuzzerCellArea.c | ||
src/apps/fuzzers/fuzzerExactEdgeLength.c | ||
src/apps/fuzzers/fuzzerCellProperties.c | ||
src/apps/fuzzers/fuzzerIndexIO.c | ||
src/apps/fuzzers/fuzzerResolutions.c | ||
src/apps/fuzzers/fuzzerHierarchy.c | ||
src/apps/fuzzers/fuzzerVertexes.c | ||
src/apps/fuzzers/fuzzerCompact.c | ||
src/apps/fuzzers/fuzzerDirectedEdge.c | ||
src/apps/fuzzers/fuzzerLocalIj.c | ||
src/apps/fuzzers/fuzzerPolygonToCells.c | ||
src/apps/benchmarks/benchmarkPolygonToCells.c | ||
src/apps/benchmarks/benchmarkPolygon.c | ||
src/apps/benchmarks/benchmarkH3SetToLinkedGeo.c | ||
|
@@ -635,12 +656,28 @@ if(BUILD_FUZZERS) | |
|
||
macro(add_h3_fuzzer name srcfile) | ||
add_h3_executable(${name} ${srcfile} ${APP_SOURCE_FILES}) | ||
if(ENABLE_LIBFUZZER) | ||
target_compile_definitions(${name} PRIVATE H3_USE_LIBFUZZER) | ||
endif() | ||
add_dependencies(fuzzers ${name}) | ||
endmacro() | ||
|
||
add_h3_fuzzer(fuzzerLatLngToCell src/apps/fuzzers/fuzzerLatLngToCell.c) | ||
add_h3_fuzzer(fuzzerCellToLatLng src/apps/fuzzers/fuzzerCellToLatLng.c) | ||
add_h3_fuzzer(fuzzerGridDisk src/apps/fuzzers/fuzzerGridDisk.c) | ||
add_h3_fuzzer(fuzzerH3SetToLinkedGeo src/apps/fuzzers/fuzzerH3SetToLinkedGeo.c) | ||
add_h3_fuzzer(fuzzerDistances src/apps/fuzzers/fuzzerDistances.c) | ||
add_h3_fuzzer(fuzzerCellArea src/apps/fuzzers/fuzzerCellArea.c) | ||
add_h3_fuzzer(fuzzerExactEdgeLength src/apps/fuzzers/fuzzerExactEdgeLength.c) | ||
add_h3_fuzzer(fuzzerCellProperties src/apps/fuzzers/fuzzerCellProperties.c) | ||
add_h3_fuzzer(fuzzerIndexIO src/apps/fuzzers/fuzzerIndexIO.c) | ||
add_h3_fuzzer(fuzzerResolutions src/apps/fuzzers/fuzzerResolutions.c) | ||
add_h3_fuzzer(fuzzerHierarchy src/apps/fuzzers/fuzzerHierarchy.c) | ||
add_h3_fuzzer(fuzzerVertexes src/apps/fuzzers/fuzzerVertexes.c) | ||
add_h3_fuzzer(fuzzerCompact src/apps/fuzzers/fuzzerCompact.c) | ||
add_h3_fuzzer(fuzzerDirectedEdge src/apps/fuzzers/fuzzerDirectedEdge.c) | ||
add_h3_fuzzer(fuzzerLocalIj src/apps/fuzzers/fuzzerLocalIj.c) | ||
add_h3_fuzzer(fuzzerPolygonToCells src/apps/fuzzers/fuzzerPolygonToCells.c) | ||
endif() | ||
|
||
if(BUILD_BENCHMARKS) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Copyright 2021 Uber Technologies, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
/** @file aflHarness.h | ||
* @brief Adapter from LLVM fuzzer to AFL++ | ||
*/ | ||
#ifndef AFLHARNESS_H | ||
#define AFLHARNESS_H | ||
|
||
#include <string.h> | ||
|
||
#include "utility.h" | ||
|
||
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size); | ||
|
||
#ifndef H3_USE_LIBFUZZER | ||
|
||
/** | ||
* Generate a AFL++ test case file of the right size initialized to all zeroes. | ||
* | ||
* @param filename | ||
* @param expectedSize | ||
* @return int | ||
*/ | ||
int generateTestCase(const char *filename, size_t expectedSize) { | ||
FILE *fp = fopen(filename, "wb"); | ||
uint8_t zero = 0; | ||
if (fwrite(&zero, sizeof(zero), expectedSize, fp) != expectedSize) { | ||
error("Error writing\n"); | ||
} | ||
fclose(fp); | ||
return 0; | ||
} | ||
|
||
#define AFL_HARNESS_MAIN(expectedSize) \ | ||
int main(int argc, char *argv[]) { \ | ||
if (argc == 3) { \ | ||
if (strcmp(argv[1], "--generate") != 0) { \ | ||
error( \ | ||
"Invalid option (should be --generate, otherwise look at " \ | ||
"aflHarness.h to see options)"); \ | ||
} \ | ||
return generateTestCase(argv[2], expectedSize); \ | ||
} \ | ||
if (argc != 2) { \ | ||
error("Should have one argument (test case file)\n"); \ | ||
} \ | ||
const char *filename = argv[1]; \ | ||
FILE *fp = fopen(filename, "rb"); \ | ||
uint8_t data[expectedSize]; \ | ||
if (fread(&data, expectedSize, 1, fp) != 1) { \ | ||
error("Error reading\n"); \ | ||
} \ | ||
fclose(fp); \ | ||
return LLVMFuzzerTestOneInput(data, expectedSize); \ | ||
} | ||
|
||
#else | ||
|
||
#define AFL_HARNESS_MAIN(expectedSize) | ||
|
||
#endif // H3_USE_LIBFUZZER | ||
|
||
#endif // AFLHARNESS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain the frontend part of this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
frontend
in this context means an implementation ofmain
that accepts arguments in a way that AFL can integrate with. Should I expand on the comments for this option?