diff --git a/.clusterfuzzlite/Dockerfile b/.clusterfuzzlite/Dockerfile new file mode 100644 index 0000000..715ee01 --- /dev/null +++ b/.clusterfuzzlite/Dockerfile @@ -0,0 +1,6 @@ +FROM gcr.io/oss-fuzz-base/base-builder +RUN apt-get update && apt-get install -y make autoconf automake libtool + +COPY . $SRC/ejson4cpp +COPY .clusterfuzzlite/build.sh $SRC/build.sh +WORKDIR $SRC/ejson4cpp \ No newline at end of file diff --git a/.clusterfuzzlite/README.md b/.clusterfuzzlite/README.md new file mode 100644 index 0000000..6f9c15f --- /dev/null +++ b/.clusterfuzzlite/README.md @@ -0,0 +1,2 @@ +# ClusterFuzzLite set up +This folder contains a fuzzing set for [ClusterFuzzLite](https://google.github.io/clusterfuzzlite). diff --git a/.clusterfuzzlite/build.sh b/.clusterfuzzlite/build.sh new file mode 100644 index 0000000..94a9d60 --- /dev/null +++ b/.clusterfuzzlite/build.sh @@ -0,0 +1,14 @@ +#!/bin/bash -eu + +mkdir build +cd build +export CXXFLAGS="${CXXFLAGS} -std=gnu++17" +cmake ../ +make + +# Copy all fuzzer executables to $OUT/ +$CXX $CXXFLAGS $LIB_FUZZING_ENGINE \ + $SRC/ejson4cpp/.clusterfuzzlite/fromjson_fuzzer.cpp \ + -o $OUT/fromjson_fuzzer \ + $SRC/ejson4cpp/build/libejson.a \ + -I$SRC/ejson4cpp/src/ diff --git a/.clusterfuzzlite/fromjson_fuzzer.cpp b/.clusterfuzzlite/fromjson_fuzzer.cpp new file mode 100644 index 0000000..bfae0ac --- /dev/null +++ b/.clusterfuzzlite/fromjson_fuzzer.cpp @@ -0,0 +1,26 @@ +#include + +#include "ejson/parser.h" + +struct person +{ + std::string name; + int id{}; + double val; +}; + +AUTO_GEN_NON_INTRUSIVE(person, name, id, val) + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + std::string fuzz_input(reinterpret_cast(data), size); + person p; + try + { + ejson::Parser::FromJSON(fuzz_input.c_str(), p); + } + catch (...) + { + } + return 0; +} \ No newline at end of file diff --git a/.clusterfuzzlite/project.yaml b/.clusterfuzzlite/project.yaml new file mode 100644 index 0000000..7f563eb --- /dev/null +++ b/.clusterfuzzlite/project.yaml @@ -0,0 +1 @@ +language: c++ \ No newline at end of file diff --git a/.github/workflows/cflite_pr.yml b/.github/workflows/cflite_pr.yml new file mode 100644 index 0000000..a6ddd01 --- /dev/null +++ b/.github/workflows/cflite_pr.yml @@ -0,0 +1,30 @@ +name: ClusterFuzzLite PR fuzzing +on: + workflow_dispatch: + pull_request: + branches: [ master ] +permissions: read-all +jobs: + PR: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + sanitizer: [address] + steps: + - name: Build Fuzzers (${{ matrix.sanitizer }}) + id: build + uses: google/clusterfuzzlite/actions/build_fuzzers@v1 + with: + sanitizer: ${{ matrix.sanitizer }} + language: c++ + bad-build-check: false + - name: Run Fuzzers (${{ matrix.sanitizer }}) + id: run + uses: google/clusterfuzzlite/actions/run_fuzzers@v1 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + fuzz-seconds: 100 + mode: 'code-change' + report-unreproducible-crashes: false + sanitizer: ${{ matrix.sanitizer }}