From ce2c83321b054a664cc852434db3351510689670 Mon Sep 17 00:00:00 2001 From: David Korczynski Date: Thu, 9 May 2024 14:00:41 -0700 Subject: [PATCH 1/2] Add clusterfuzz lite integration Signed-off-by: David Korczynski --- .clusterfuzzlite/Dockerfile | 8 ++++++++ .clusterfuzzlite/build.sh | 10 ++++++++++ .clusterfuzzlite/fuzzer.c | 26 ++++++++++++++++++++++++++ .clusterfuzzlite/project.yaml | 1 + .github/workflows/cflite_pr.yml | 30 ++++++++++++++++++++++++++++++ 5 files changed, 75 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..4eb044b --- /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/libjson +COPY .clusterfuzzlite/build.sh $SRC/build.sh +COPY .clusterfuzzlite/*.cpp $SRC/ +COPY .clusterfuzzlite/*.c $SRC/ +WORKDIR libjson diff --git a/.clusterfuzzlite/build.sh b/.clusterfuzzlite/build.sh new file mode 100644 index 0000000..51c2650 --- /dev/null +++ b/.clusterfuzzlite/build.sh @@ -0,0 +1,10 @@ +#!/bin/bash +for file in "jsonlint.c json.c"; do + $CC $CFLAGS -c ${file} +done + +rm -f ./test*.o +llvm-ar rcs libfuzz.a *.o + + +$CC $CFLAGS $LIB_FUZZING_ENGINE $SRC/fuzzer.c -Wl,--whole-archive $SRC/libjson/libfuzz.a -Wl,--allow-multiple-definition -I$SRC/libjson/ -o $OUT/fuzzer diff --git a/.clusterfuzzlite/fuzzer.c b/.clusterfuzzlite/fuzzer.c new file mode 100644 index 0000000..0cdb811 --- /dev/null +++ b/.clusterfuzzlite/fuzzer.c @@ -0,0 +1,26 @@ +#include +#include +#include +#include + +#include "json.h" + +int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { + FILE *input = fmemopen((void *)data, size, "r"); + if (!input) { + return 0; + } + + json_parser parser; + json_parser_init(&parser, NULL, NULL, NULL); + + int ret = 0; + int lines, col; + ret = process_file(&parser, input, &lines, &col); + + json_parser_free(&parser); + fclose(input); + + 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 }} From 48cec6a01c3dd04aeeba22f2380b59de33d049bb Mon Sep 17 00:00:00 2001 From: David Korczynski Date: Thu, 9 May 2024 16:07:21 -0700 Subject: [PATCH 2/2] cleanup Signed-off-by: David Korczynski --- .clusterfuzzlite/Dockerfile | 1 - .clusterfuzzlite/build.sh | 1 - 2 files changed, 2 deletions(-) diff --git a/.clusterfuzzlite/Dockerfile b/.clusterfuzzlite/Dockerfile index 4eb044b..ca88327 100644 --- a/.clusterfuzzlite/Dockerfile +++ b/.clusterfuzzlite/Dockerfile @@ -3,6 +3,5 @@ RUN apt-get update && apt-get install -y make autoconf automake libtool cmake \ pkg-config curl check COPY . $SRC/libjson COPY .clusterfuzzlite/build.sh $SRC/build.sh -COPY .clusterfuzzlite/*.cpp $SRC/ COPY .clusterfuzzlite/*.c $SRC/ WORKDIR libjson diff --git a/.clusterfuzzlite/build.sh b/.clusterfuzzlite/build.sh index 51c2650..1454eb2 100644 --- a/.clusterfuzzlite/build.sh +++ b/.clusterfuzzlite/build.sh @@ -3,7 +3,6 @@ for file in "jsonlint.c json.c"; do $CC $CFLAGS -c ${file} done -rm -f ./test*.o llvm-ar rcs libfuzz.a *.o