Skip to content

Setup Fuzzing #3

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: CI Fuzz
# Set an action secret called "CI_FUZZ_API_TOKEN" with an API token
# generated in CI Fuzz web interface.

on:
workflow_dispatch:
push:
branches: [ main ]
pull_request:
branches: [ main ]

env:
# CI Sense gRPC URL.
FUZZING_SERVER_ADDRESS: grpc.code-intelligence.com:443
# CI Sense HTTP URL.
WEB_APP_ADDRESS: https://app.code-intelligence.com
# Directory in which the repository will be cloned.
CHECKOUT_DIR: checkout-dir/
CIFUZZ_DOWNLOAD_URL: "https://github.com/CodeIntelligenceTesting/cifuzz/releases/latest/download/cifuzz_installer_linux_amd64"
CIFUZZ_INSTALL_DIR: ./cifuzz
FUZZING_ARTIFACT: fuzzing-artifact.tar.gz
jobs:
fuzz_tests:
runs-on: ubuntu-latest
container: cifuzz/builder-zint:llvm-13
steps:
- id: checkout
name: Checkout Repository
uses: actions/checkout@v2
with:
path: ${{ env.CHECKOUT_DIR }}
- id: install-cifuzz
name: Install cifuzz
run: |
curl --fail --silent --show-error --location -o cifuzz_installer "$CIFUZZ_DOWNLOAD_URL"
chmod u+x cifuzz_installer
./cifuzz_installer --install-dir $CIFUZZ_INSTALL_DIR
- id: install-depdendencies
name: Install Dependencies
run: |
apt-get update && apt-get install -y libssl-dev
- id: build-fuzzers
name: Build Fuzzers
run: |
export cifuzz_DIR="$GITHUB_WORKSPACE/$CIFUZZ_INSTALL_DIR/share/cmake"
cd $CHECKOUT_DIR/
$GITHUB_WORKSPACE/$CIFUZZ_INSTALL_DIR/bin/cifuzz bundle \
--commit $GITHUB_SHA \
--branch $GITHUB_REF_NAME \
--output $GITHUB_WORKSPACE/$CHECKOUT_DIR/$FUZZING_ARTIFACT
shell: "bash"
- id: start-fuzzing
name: Start Fuzzing
uses: CodeIntelligenceTesting/github-actions/start-fuzzing@v5
with:
ci_fuzz_api_token: ${{ secrets.CI_FUZZ_API_TOKEN }}
fuzzing_server_address: ${{ env.FUZZING_SERVER_ADDRESS }}
fuzzing_artifact: ${{ env.CHECKOUT_DIR }}/${{ env.FUZZING_ARTIFACT }}
checkout_directory: ${{ env.CHECKOUT_DIR }}
project: "projects/prj-ho58fmjYVGuQ"
- id: monitor-fuzzing
name: Fuzzing
uses: CodeIntelligenceTesting/github-actions/monitor-fuzzing@v5
with:
ci_fuzz_api_token: ${{ secrets.CI_FUZZ_API_TOKEN }}
test_collection_run: ${{ steps.start-fuzzing.outputs.test_collection_run }}
fuzzing_server_address: ${{ env.FUZZING_SERVER_ADDRESS }}
dashboard_address: ${{ env.WEB_APP_ADDRESS }}
- id: save-results
name: Save Fuzz Test Results
uses: CodeIntelligenceTesting/github-actions/save-results@v5
if: ${{ success() || failure() }}
with:
ci_fuzz_api_token: ${{ secrets.CI_FUZZ_API_TOKEN }}
test_collection_run: ${{ steps.start-fuzzing.outputs.test_collection_run }}
fuzzing_server_address: ${{ env.FUZZING_SERVER_ADDRESS }}
dashboard_address: ${{ env.WEB_APP_ADDRESS }}
- id: upload-artifact
uses: actions/upload-artifact@v2
if: ${{ (success() || failure()) }}
with:
name: ci_fuzz_results
path: |
findings.json
coverage.json
web_app_address.txt
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@ set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/external)
enable_testing()
include(googletest)

find_package(cifuzz NO_SYSTEM_ENVIRONMENT_PATH)
enable_fuzz_testing()

add_subdirectory(src/explore_me)
add_subdirectory(src/automotive)
add_subdirectory(src/automotive)
100 changes: 100 additions & 0 deletions CMakeUserPresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
{
"version": 3,
"cmakeMinimumRequired": {
"major": 3,
"minor": 20,
"patch": 0
},
"configurePresets": [
{
"name": "cifuzz (Coverage)",
"displayName": "cifuzz (Coverage)",
"binaryDir": "${sourceDir}/.cifuzz-build/replayer/gcov",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "RelWithDebInfo",
"CIFUZZ_ENGINE": "replayer",
"CIFUZZ_SANITIZERS": "gcov",
"CIFUZZ_TESTING": {
"type": "BOOL",
"value": "ON"
},
"CMAKE_BUILD_RPATH_USE_ORIGIN": {
"type": "BOOL",
"value": "ON"
}
}
},
{
"name": "cifuzz (Fuzzing)",
"displayName": "cifuzz (Fuzzing)",
"binaryDir": "${sourceDir}/.cifuzz-build/libfuzzer/address+undefined",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "RelWithDebInfo",
"CIFUZZ_ENGINE": "libfuzzer",
"CIFUZZ_SANITIZERS": "address;undefined",
"CIFUZZ_TESTING": {
"type": "BOOL",
"value": "ON"
},
"CMAKE_BUILD_RPATH_USE_ORIGIN": {
"type": "BOOL",
"value": "ON"
}
},
"environment": {
"CC": "clang",
"CXX": "clang++"
}
},
{
"name": "cifuzz (Regression Test)",
"displayName": "cifuzz (Regression Test)",
"binaryDir": "${sourceDir}/.cifuzz-build/replayer/address+undefined",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "RelWithDebInfo",
"CIFUZZ_ENGINE": "replayer",
"CIFUZZ_SANITIZERS": "address;undefined",
"CIFUZZ_TESTING": {
"type": "BOOL",
"value": "ON"
},
"CMAKE_BUILD_RPATH_USE_ORIGIN": {
"type": "BOOL",
"value": "ON"
}
}
}
],
"buildPresets": [
{
"name": "cifuzz (Coverage)",
"displayName": "cifuzz (Coverage)",
"configurePreset": "cifuzz (Coverage)",
"configuration": "RelWithDebInfo"
},
{
"name": "cifuzz (Fuzzing)",
"displayName": "cifuzz (Fuzzing)",
"configurePreset": "cifuzz (Fuzzing)",
"configuration": "RelWithDebInfo"
},
{
"name": "cifuzz (Regression Test)",
"displayName": "cifuzz (Regression Test)",
"configurePreset": "cifuzz (Regression Test)",
"configuration": "RelWithDebInfo"
}
],
"testPresets": [
{
"name": "cifuzz (Regression Test)",
"displayName": "cifuzz (Regression Test)",
"configurePreset": "cifuzz (Regression Test)",
"filter": {
"include": {
"label": "^cifuzz_regression_test$"
}
}
}
]
}
46 changes: 46 additions & 0 deletions cifuzz.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
## Configuration for a CI Fuzz project
## Generated on 2023-06-06

## The build system used to build this project. If not set, cifuzz tries
## to detect the build system automatically.
## Valid values: "bazel", "cmake", "maven", "gradle", "other".
#build-system: cmake

## If the build system type is "other", this command is used by
## `cifuzz run` to build the fuzz test.
#build-command: "make my_fuzz_test"

## Directories containing sample inputs for the code under test.
## See https://llvm.org/docs/LibFuzzer.html#corpus
#seed-corpus-dirs:
# - path/to/seed-corpus

## A file containing input language keywords or other interesting byte
## sequences.
## See https://llvm.org/docs/LibFuzzer.html#dictionaries
#dict: path/to/dictionary.dct

## Command-line arguments to pass to libFuzzer.
## See https://llvm.org/docs/LibFuzzer.html#options
engine-args:
- -use_value_profile=1

## Maximum time to run fuzz tests. The default is to run indefinitely.
#timeout: 30m

## By default, fuzz tests are executed in a sandbox to prevent accidental
## damage to the system. Set to false to run fuzz tests unsandboxed.
## Only supported on Linux.
#use-sandbox: false

## Set to true to print output of the `cifuzz run` command as JSON.
#print-json: true

## Set to true to disable desktop notifications
#no-notifications: true

## Set URL of the CI App
#server: https://app.code-intelligence.com

## Set the project name on the CI App
#project: my-project-1a2b3c4d
11 changes: 10 additions & 1 deletion src/automotive/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,13 @@ target_include_directories(automotive PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/gps
${CMAKE_CURRENT_SOURCE_DIR}/key_management
${CMAKE_CURRENT_SOURCE_DIR}/time
)
)

add_fuzz_test(automotive_fuzzer
fuzz_test.cpp
mocks.cpp
)

target_link_libraries(automotive_fuzzer
automotive
)
Loading