From 072b37dfaab6c4c337f4ec950ce1892206272221 Mon Sep 17 00:00:00 2001 From: David Korczynski Date: Sat, 11 May 2024 04:21:34 -0700 Subject: [PATCH 1/2] Add ClusterFuzzLite integration Signed-off-by: David Korczynski --- .clusterfuzzlite/Dockerfile | 8 ++++++++ .clusterfuzzlite/build.sh | 6 ++++++ .clusterfuzzlite/fuzzer.c | 27 +++++++++++++++++++++++++++ .clusterfuzzlite/project.yaml | 1 + .github/workflows/cflite_pr.yml | 30 ++++++++++++++++++++++++++++++ 5 files changed, 72 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..e839afa --- /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/lorawan-parser +COPY .clusterfuzzlite/build.sh $SRC/build.sh +COPY .clusterfuzzlite/*.cpp $SRC/ +COPY .clusterfuzzlite/*.c $SRC/ +WORKDIR lorawan-parser diff --git a/.clusterfuzzlite/build.sh b/.clusterfuzzlite/build.sh new file mode 100644 index 0000000..b0fbfb5 --- /dev/null +++ b/.clusterfuzzlite/build.sh @@ -0,0 +1,6 @@ +#!/bin/bash +autoreconf -fi +./configure +make + +$CC $CFLAGS $LIB_FUZZING_ENGINE $SRC/fuzzer.c -Wl,--whole-archive $SRC/lorawan-parser/lw/.libs/liblorawan.a -Wl,--whole-archive $SRC/lorawan-parser/lib/libloragw$SRC/.libs/libloragw.a -Wl,--whole-archive $SRC/lorawan-parser/lib/.libs/lib.a -Wl,--allow-multiple-definition -I$SRC/lorawan-parser/util/parser -I$SRC/lorawan-parser/lib/libloragw/inc -I$SRC/lorawan-parser/lib -I$SRC/lorawan-parser/lw -o $OUT/fuzzer \ No newline at end of file diff --git a/.clusterfuzzlite/fuzzer.c b/.clusterfuzzlite/fuzzer.c new file mode 100644 index 0000000..1c6a132 --- /dev/null +++ b/.clusterfuzzlite/fuzzer.c @@ -0,0 +1,27 @@ +#include +#include +#include +#include + +#include +#include +#include "json.h" + +int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { + if (size == 0) + return 0; + + // Ensure `data` is null-terminated + char input[size + 1]; + memcpy(input, data, size); + input[size] = '\0'; + + // Call the target function with the input + JsonNode *result = json_decode((const char *)input); + + // Free the result to avoid memory leaks + json_delete(result); + + 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 f88f5d62b5fef63cbe3fc2ff280684ad7001fcc8 Mon Sep 17 00:00:00 2001 From: David Korczynski Date: Sat, 11 May 2024 04:24:49 -0700 Subject: [PATCH 2/2] cleanup Signed-off-by: David Korczynski --- .clusterfuzzlite/Dockerfile | 4 +--- .clusterfuzzlite/build.sh | 2 +- .clusterfuzzlite/fuzzer.c | 4 ---- 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/.clusterfuzzlite/Dockerfile b/.clusterfuzzlite/Dockerfile index e839afa..9dbf753 100644 --- a/.clusterfuzzlite/Dockerfile +++ b/.clusterfuzzlite/Dockerfile @@ -1,8 +1,6 @@ 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 +RUN apt-get update && apt-get install -y make autoconf automake libtool COPY . $SRC/lorawan-parser COPY .clusterfuzzlite/build.sh $SRC/build.sh -COPY .clusterfuzzlite/*.cpp $SRC/ COPY .clusterfuzzlite/*.c $SRC/ WORKDIR lorawan-parser diff --git a/.clusterfuzzlite/build.sh b/.clusterfuzzlite/build.sh index b0fbfb5..dc04f91 100644 --- a/.clusterfuzzlite/build.sh +++ b/.clusterfuzzlite/build.sh @@ -3,4 +3,4 @@ autoreconf -fi ./configure make -$CC $CFLAGS $LIB_FUZZING_ENGINE $SRC/fuzzer.c -Wl,--whole-archive $SRC/lorawan-parser/lw/.libs/liblorawan.a -Wl,--whole-archive $SRC/lorawan-parser/lib/libloragw$SRC/.libs/libloragw.a -Wl,--whole-archive $SRC/lorawan-parser/lib/.libs/lib.a -Wl,--allow-multiple-definition -I$SRC/lorawan-parser/util/parser -I$SRC/lorawan-parser/lib/libloragw/inc -I$SRC/lorawan-parser/lib -I$SRC/lorawan-parser/lw -o $OUT/fuzzer \ No newline at end of file +$CC $CFLAGS $LIB_FUZZING_ENGINE $SRC/fuzzer.c -Wl,--whole-archive $SRC/lorawan-parser/lw/.libs/liblorawan.a -Wl,--whole-archive $SRC/lorawan-parser/lib/libloragw$SRC/.libs/libloragw.a -Wl,--whole-archive $SRC/lorawan-parser/lib/.libs/lib.a -Wl,--allow-multiple-definition -I$SRC/lorawan-parser/util/parser -I$SRC/lorawan-parser/lib/libloragw/inc -I$SRC/lorawan-parser/lib -I$SRC/lorawan-parser/lw -o $OUT/fuzzer diff --git a/.clusterfuzzlite/fuzzer.c b/.clusterfuzzlite/fuzzer.c index 1c6a132..d956d9e 100644 --- a/.clusterfuzzlite/fuzzer.c +++ b/.clusterfuzzlite/fuzzer.c @@ -1,8 +1,4 @@ -#include -#include -#include #include - #include #include #include "json.h"