From 6d771f159985c631299aefa6146a5b8d018451eb Mon Sep 17 00:00:00 2001 From: David Korczynski Date: Sat, 23 Dec 2023 02:45:00 -0800 Subject: [PATCH] Add fuzzing by way of ClusterFuzzLite Signed-off-by: David Korczynski --- .clusterfuzzlite/Dockerfile | 6 ++++++ .clusterfuzzlite/README.md | 3 +++ .clusterfuzzlite/build.sh | 14 ++++++++++++++ .clusterfuzzlite/parser_fuzzer.cpp | 17 +++++++++++++++++ .clusterfuzzlite/project.yaml | 1 + .github/workflows/cflite_pr.yml | 30 ++++++++++++++++++++++++++++++ 6 files changed, 71 insertions(+) create mode 100644 .clusterfuzzlite/Dockerfile create mode 100644 .clusterfuzzlite/README.md create mode 100644 .clusterfuzzlite/build.sh create mode 100644 .clusterfuzzlite/parser_fuzzer.cpp create mode 100644 .clusterfuzzlite/project.yaml create mode 100644 .github/workflows/cflite_pr.yml diff --git a/.clusterfuzzlite/Dockerfile b/.clusterfuzzlite/Dockerfile new file mode 100644 index 0000000..d7c3da8 --- /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/muparserx +COPY .clusterfuzzlite/build.sh $SRC/build.sh +WORKDIR $SRC/muparserx diff --git a/.clusterfuzzlite/README.md b/.clusterfuzzlite/README.md new file mode 100644 index 0000000..4ee95c0 --- /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). diff --git a/.clusterfuzzlite/build.sh b/.clusterfuzzlite/build.sh new file mode 100644 index 0000000..cd87f10 --- /dev/null +++ b/.clusterfuzzlite/build.sh @@ -0,0 +1,14 @@ +#!/bin/bash -eu + +mkdir build +cd build +cmake ../ +make + +# Copy all fuzzer executables to $OUT/ +$CXX $CFLAGS $LIB_FUZZING_ENGINE \ + $SRC/muparserx/.clusterfuzzlite/parser_fuzzer.cpp \ + -stdlib=libc++ -std=c++17 \ + -o $OUT/parser_fuzzer \ + -I$SRC/muparserx/parser \ + $SRC/muparserx/build/libmuparserx.a diff --git a/.clusterfuzzlite/parser_fuzzer.cpp b/.clusterfuzzlite/parser_fuzzer.cpp new file mode 100644 index 0000000..ff27258 --- /dev/null +++ b/.clusterfuzzlite/parser_fuzzer.cpp @@ -0,0 +1,17 @@ +#include "mpParser.h" +#include + +using namespace mup; + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { + std::string fuzz_input(reinterpret_cast(data), size); + ParserX p; + + try { + p.SetExpr(fuzz_input); + p.Eval(); + } catch (...) { + } + + return 0; +} diff --git a/.clusterfuzzlite/project.yaml b/.clusterfuzzlite/project.yaml new file mode 100644 index 0000000..b478801 --- /dev/null +++ b/.clusterfuzzlite/project.yaml @@ -0,0 +1 @@ +language: c++ diff --git a/.github/workflows/cflite_pr.yml b/.github/workflows/cflite_pr.yml new file mode 100644 index 0000000..d17530b --- /dev/null +++ b/.github/workflows/cflite_pr.yml @@ -0,0 +1,30 @@ +name: ClusterFuzzLite PR fuzzing +on: + workflow_dispatch: + pull_request: + branches: [ main ] +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: 180 + mode: 'code-change' + report-unreproducible-crashes: false + sanitizer: ${{ matrix.sanitizer }}