diff --git a/.clusterfuzzlite/Dockerfile b/.clusterfuzzlite/Dockerfile new file mode 100644 index 00000000..64f11f41 --- /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/argparse +COPY .clusterfuzzlite/build.sh $SRC/build.sh +WORKDIR $SRC/argparse \ No newline at end of file diff --git a/.clusterfuzzlite/README.md b/.clusterfuzzlite/README.md new file mode 100644 index 00000000..01b79f52 --- /dev/null +++ b/.clusterfuzzlite/README.md @@ -0,0 +1,3 @@ +# ClusterFuzzLite set up + +This folder contains a fuzzing set for [ClusterFuzzLite](https://google.github.io/clusterfuzzlite). \ No newline at end of file diff --git a/.clusterfuzzlite/build.sh b/.clusterfuzzlite/build.sh new file mode 100644 index 00000000..5325a2d8 --- /dev/null +++ b/.clusterfuzzlite/build.sh @@ -0,0 +1,6 @@ +# Copy all fuzzer executables to $OUT/ +$CXX $CFLAGS $LIB_FUZZING_ENGINE \ + $SRC/argparse/.clusterfuzzlite/fuzz_argparse.cpp \ + -o $OUT/fuzz_argparse \ + -std=gnu++17 \ + -I$SRC/argparse/include \ No newline at end of file diff --git a/.clusterfuzzlite/fuzz_argparse.cpp b/.clusterfuzzlite/fuzz_argparse.cpp new file mode 100644 index 00000000..70e313fa --- /dev/null +++ b/.clusterfuzzlite/fuzz_argparse.cpp @@ -0,0 +1,34 @@ +#include +#include +#include + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { + FuzzedDataProvider fdp(data, size); + + int args_to_generate = fdp.ConsumeIntegralInRange(1, 10); + std::vector fuzz_args; + for (int i = 0; i < args_to_generate; i++) { + fuzz_args.push_back(fdp.ConsumeRandomLengthString()); + } + + // Ensure none of the strings have sequences that cause exit: + // "-h", "--help", "-v", "--version" + for (int i = 0; i < args_to_generate; i++) { + if (fuzz_args[i].find("-h") != std::string::npos || + fuzz_args[i].find("-v") != std::string::npos) { + return 0; + } + } + + argparse::ArgumentParser program("test"); + program.add_argument("--config"); + program.add_argument("--test"); + program.add_argument("--fuzzval"); + program.add_argument("--param"); + try { + program.parse_args(fuzz_args); + } catch (...) { + } + + return 0; +} \ No newline at end of file diff --git a/.clusterfuzzlite/project.yaml b/.clusterfuzzlite/project.yaml new file mode 100644 index 00000000..7f563eb7 --- /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 00000000..917c553c --- /dev/null +++ b/.github/workflows/cflite_pr.yml @@ -0,0 +1,28 @@ +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 }}) + uses: google/clusterfuzzlite/actions/build_fuzzers@v1 + with: + sanitizer: ${{ matrix.sanitizer }} + language: c++ + bad-build-check: false + - name: Run Fuzzers (${{ matrix.sanitizer }}) + uses: google/clusterfuzzlite/actions/run_fuzzers@v1 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + fuzz-seconds: 120 + mode: 'code-change' + report-unreproducible-crashes: false + sanitizer: ${{ matrix.sanitizer }}