-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
95 additions
and
4 deletions.
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,2 @@ | ||
fuzz/build/ | ||
fuzz/corpus/ |
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,18 @@ | ||
cmake_minimum_required(VERSION 3.10) | ||
|
||
project(essence_fuzzer) | ||
|
||
set(CMAKE_C_STANDARD 99) | ||
|
||
include_directories(. ../src ../src/iota) | ||
|
||
add_definitions(-DFUZZING) | ||
|
||
add_executable(essence_fuzzer fuzztest.c ../src/iota/essence.c) | ||
add_executable(essence_fuzzer_coverage fuzztest.c ../src/iota/essence.c) | ||
|
||
target_compile_options(essence_fuzzer PRIVATE -fsanitize=fuzzer,address -g -ggdb2 -O1) | ||
target_compile_options(essence_fuzzer_coverage PRIVATE -fsanitize=fuzzer,address -g -ggdb2 -O1 -fprofile-instr-generate -fcoverage-mapping) | ||
|
||
target_link_options(essence_fuzzer PRIVATE -fsanitize=fuzzer,address) | ||
target_link_options(essence_fuzzer_coverage PRIVATE -fsanitize=fuzzer,address) |
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,36 @@ | ||
## Fuzzing | ||
|
||
This fuzzer should reach a reasonable coverage (>85%) of `essence.c` with no test cases to start with and in a very short time, but this could always be improved by starting from a real testcase. | ||
|
||
### On Linux: | ||
|
||
- `cmake -Bbuild -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++` | ||
|
||
Fuzzing (from `./build/`): | ||
|
||
- `./essence_fuzzer ../corpus/` | ||
|
||
Running coverage: | ||
|
||
- `./essence_fuzzer_coverage ../corpus/*` | ||
|
||
### On Windows: | ||
|
||
- `cmake -Bbuild -GNinja -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++` | ||
|
||
Fuzzing (from `./build/`): | ||
|
||
- `.\essence_fuzzer.exe ../corpus/` | ||
|
||
Running coverage: | ||
- `.\essence_fuzzer_coverage.exe $(ls ../corpus/* | % {$_.FullName})` | ||
|
||
## Monitoring coverage | ||
|
||
``` | ||
llvm-profdata merge -sparse *.profraw -o default.profdata | ||
llvm-cov report essence_fuzzer_coverage -instr-profile="default.profdata" | ||
llvm-cov show essence_fuzzer_coverage -instr-profile="default.profdata" --format=html > report.html | ||
``` | ||
|
||
Will output a file `report.html` containing coverage information by line in the source file. |
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,15 @@ | ||
#include <stdint.h> | ||
#include <string.h> | ||
|
||
#include "api.h" | ||
#include "essence.h" | ||
|
||
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { | ||
if (Size >= API_BUFFER_SIZE_BYTES) { | ||
API_CTX api = {0}; | ||
memcpy(api.data.buffer, Data, API_BUFFER_SIZE_BYTES); | ||
// api.essence.has_remainder = 1; | ||
essence_parse_and_validate(&api); | ||
} | ||
return 0; | ||
} |
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,7 @@ | ||
#pragma once | ||
|
||
#define os_memcpy memcpy | ||
#define os_memcmp memcmp | ||
#define os_memset memset | ||
#define explicit_bzero(addr, size) memset((addr), 0, (size)) | ||
|
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