From 73e95e6c2daac50c6cb35c9c9ba9bb5fb421cceb Mon Sep 17 00:00:00 2001 From: David Korczynski Date: Thu, 21 Dec 2023 14:49:17 -0800 Subject: [PATCH 1/2] Add fuzzing by way of ClusterFuzzLite Signed-off-by: David Korczynski --- .clusterfuzzlite/Dockerfile | 6 ++++++ .clusterfuzzlite/README.md | 3 +++ .clusterfuzzlite/build.sh | 6 ++++++ .clusterfuzzlite/mjson_fuzzer.c | 22 ++++++++++++++++++++++ .clusterfuzzlite/project.yaml | 1 + .github/workflows/cflite_pr.yml | 30 ++++++++++++++++++++++++++++++ 6 files changed, 68 insertions(+) create mode 100644 .clusterfuzzlite/Dockerfile create mode 100644 .clusterfuzzlite/README.md create mode 100644 .clusterfuzzlite/build.sh create mode 100644 .clusterfuzzlite/mjson_fuzzer.c 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..e33f5b6 --- /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/mjson +COPY .clusterfuzzlite/build.sh $SRC/build.sh +WORKDIR $SRC/mjson \ No newline at end of file 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..fa1208f --- /dev/null +++ b/.clusterfuzzlite/build.sh @@ -0,0 +1,6 @@ +#!/bin/bash -eu +# Copy all fuzzer executables to $OUT/ +$CC $CFLAGS $LIB_FUZZING_ENGINE \ + $SRC/mjson/.clusterfuzzlite/mjson_fuzzer.c \ + -o $OUT/mjson_fuzzer \ + $SRC/mjson/src/mjson.c -I$SRC/mjson/src/ diff --git a/.clusterfuzzlite/mjson_fuzzer.c b/.clusterfuzzlite/mjson_fuzzer.c new file mode 100644 index 0000000..993cc4e --- /dev/null +++ b/.clusterfuzzlite/mjson_fuzzer.c @@ -0,0 +1,22 @@ +#include +#include +#include + +#include + +int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { + if (size == 0) { + return 0; + } + uint8_t decider = data[0]; + size -= 1; + data++; + + if ((decider % 2) == 0) { + mjson((const char *)data, size, NULL, NULL); + } else { + mjson_find((const char *)data, size, "$.a", NULL, NULL); + } + + return 0; +} \ No newline at end of file diff --git a/.clusterfuzzlite/project.yaml b/.clusterfuzzlite/project.yaml new file mode 100644 index 0000000..e196c5c --- /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..04056ab --- /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: 100 + mode: 'code-change' + report-unreproducible-crashes: false + sanitizer: ${{ matrix.sanitizer }} From 3200b6eddbd2e6c1dc2193057eb38db3da456309 Mon Sep 17 00:00:00 2001 From: David Korczynski Date: Sat, 23 Dec 2023 03:20:16 -0800 Subject: [PATCH 2/2] cflite: fix branch name Signed-off-by: David Korczynski --- .github/workflows/cflite_pr.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cflite_pr.yml b/.github/workflows/cflite_pr.yml index 04056ab..93de02a 100644 --- a/.github/workflows/cflite_pr.yml +++ b/.github/workflows/cflite_pr.yml @@ -2,7 +2,7 @@ name: ClusterFuzzLite PR fuzzing on: workflow_dispatch: pull_request: - branches: [ main ] + branches: [ master ] permissions: read-all jobs: PR: