From df6820a1c0fccf14b21b24237b21371935026581 Mon Sep 17 00:00:00 2001 From: David Korczynski Date: Sat, 11 May 2024 05:00:30 -0700 Subject: [PATCH 1/2] Add ClusterFuzzLite integration Signed-off-by: David Korczynski --- .clusterfuzzlite/Dockerfile | 8 ++++++++ .clusterfuzzlite/build.sh | 9 +++++++++ .clusterfuzzlite/fuzzer.c | 27 +++++++++++++++++++++++++++ .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..84de37c --- /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/picohttpparser +COPY .clusterfuzzlite/build.sh $SRC/build.sh +COPY .clusterfuzzlite/*.cpp $SRC/ +COPY .clusterfuzzlite/*.c $SRC/ +WORKDIR picohttpparser diff --git a/.clusterfuzzlite/build.sh b/.clusterfuzzlite/build.sh new file mode 100644 index 0000000..c7b6e99 --- /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/picohttpparser/libfuzz.a -Wl,--allow-multiple-definition -I$SRC/picohttpparser/ -I$SRC/picohttpparser/picotest -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..57bdce3 --- /dev/null +++ b/.clusterfuzzlite/fuzzer.c @@ -0,0 +1,27 @@ +#include +#include +#include +#include + +#include "picohttpparser.h" +#include "picotest.h" + +int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { + if (size < 10) { + return 0; + } + + const char *buf = (const char *)data; + size_t buflen = size; + + int minor_version, status; + const char *msg; + size_t msg_len; + struct phr_header headers[100]; + size_t num_headers = sizeof(headers) / sizeof(headers[0]); + size_t prevbuflen = 0; + + phr_parse_response(buf, buflen, &minor_version, &status, &msg, &msg_len, headers, &num_headers, prevbuflen); + + 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 ef58351286a9cc30fd6c3fedc0e0757de9530a61 Mon Sep 17 00:00:00 2001 From: David Korczynski Date: Sat, 11 May 2024 05:16:09 -0700 Subject: [PATCH 2/2] cflite: cleanup Signed-off-by: David Korczynski --- .clusterfuzzlite/Dockerfile | 4 +--- .clusterfuzzlite/build.sh | 8 ++------ .clusterfuzzlite/fuzzer.c | 5 ----- 3 files changed, 3 insertions(+), 14 deletions(-) diff --git a/.clusterfuzzlite/Dockerfile b/.clusterfuzzlite/Dockerfile index 84de37c..1bef471 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/picohttpparser COPY .clusterfuzzlite/build.sh $SRC/build.sh -COPY .clusterfuzzlite/*.cpp $SRC/ COPY .clusterfuzzlite/*.c $SRC/ WORKDIR picohttpparser diff --git a/.clusterfuzzlite/build.sh b/.clusterfuzzlite/build.sh index c7b6e99..f8e2873 100644 --- a/.clusterfuzzlite/build.sh +++ b/.clusterfuzzlite/build.sh @@ -1,9 +1,5 @@ #!/bin/bash -find . -name "*.c" -exec $CC $CFLAGS -I./src -c {} \; -find . -name "*.o" -exec cp {} . \; - -rm -f ./test*.o +$CC $CFLAGS -c picohttpparser.c llvm-ar rcs libfuzz.a *.o - -$CC $CFLAGS $LIB_FUZZING_ENGINE $SRC/fuzzer.c -Wl,--whole-archive $SRC/picohttpparser/libfuzz.a -Wl,--allow-multiple-definition -I$SRC/picohttpparser/ -I$SRC/picohttpparser/picotest -o $OUT/fuzzer \ No newline at end of file +$CC $CFLAGS $LIB_FUZZING_ENGINE $SRC/fuzzer.c -Wl,--whole-archive $SRC/picohttpparser/libfuzz.a -Wl,--allow-multiple-definition -I$SRC/picohttpparser/ -o $OUT/fuzzer diff --git a/.clusterfuzzlite/fuzzer.c b/.clusterfuzzlite/fuzzer.c index 57bdce3..ec94169 100644 --- a/.clusterfuzzlite/fuzzer.c +++ b/.clusterfuzzlite/fuzzer.c @@ -1,10 +1,5 @@ -#include #include -#include -#include - #include "picohttpparser.h" -#include "picotest.h" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { if (size < 10) {