From b691ff34ff1cd7798fac951c43791f428a8d3245 Mon Sep 17 00:00:00 2001 From: David Korczynski Date: Fri, 10 May 2024 16:30:01 -0700 Subject: [PATCH] Add ClusterFuzzLite workflow Signed-off-by: David Korczynski --- .clusterfuzzlite/Dockerfile | 8 ++++++++ .clusterfuzzlite/build.sh | 9 +++++++++ .clusterfuzzlite/fuzzer.c | 26 ++++++++++++++++++++++++++ .clusterfuzzlite/project.yaml | 1 + .github/workflows/cflite_pr.yml | 30 ++++++++++++++++++++++++++++++ 5 files changed, 74 insertions(+) create mode 100644 .clusterfuzzlite/Dockerfile create mode 100644 .clusterfuzzlite/build.sh create mode 100644 .clusterfuzzlite/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..932e6e0 --- /dev/null +++ b/.clusterfuzzlite/Dockerfile @@ -0,0 +1,8 @@ +FROM gcr.io/oss-fuzz-base/base-builder +RUN apt-get update && apt-get install -y make autoconf automake libtool cmake \ + pkg-config curl check +COPY . $SRC/tiny-json +COPY .clusterfuzzlite/build.sh $SRC/build.sh +COPY .clusterfuzzlite/*.cpp $SRC/ +COPY .clusterfuzzlite/*.c $SRC/ +WORKDIR tiny-json diff --git a/.clusterfuzzlite/build.sh b/.clusterfuzzlite/build.sh new file mode 100644 index 0000000..ec95de1 --- /dev/null +++ b/.clusterfuzzlite/build.sh @@ -0,0 +1,9 @@ +#!/bin/bash +find . -name "*.c" -exec $CC $CFLAGS -I./src -c {} \; +find . -name "*.o" -exec cp {} . \; + +rm -f ./test*.o +llvm-ar rcs libfuzz.a *.o + + +$CC $CFLAGS $LIB_FUZZING_ENGINE $SRC/fuzzer.c -Wl,--whole-archive $SRC/tiny-json/libfuzz.a -Wl,--allow-multiple-definition -I$SRC/tiny-json/ -o $OUT/fuzzer diff --git a/.clusterfuzzlite/fuzzer.c b/.clusterfuzzlite/fuzzer.c new file mode 100644 index 0000000..fdef69e --- /dev/null +++ b/.clusterfuzzlite/fuzzer.c @@ -0,0 +1,26 @@ +#include +#include +#include +#include + +#include "tiny-json.h" + +int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { + // Create an input string with null-termination + char* input_string = (char*)malloc(size + 1); + if (input_string == NULL) { + return 0; + } + memcpy(input_string, data, size); + input_string[size] = '\0'; + + // Create an array of json_t for the second argument + json_t json_array[10]; // Assuming max size of 10 for simplicity + + // Call the target function with the input data + json_create(input_string, json_array, 10); + + free(input_string); + return 0; +} + diff --git a/.clusterfuzzlite/project.yaml b/.clusterfuzzlite/project.yaml new file mode 100644 index 0000000..b455aa3 --- /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..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 }}