From 3b8fc10cf25f8cdeb1a26e6410e0d14657b754d6 Mon Sep 17 00:00:00 2001 From: David Korczynski Date: Thu, 9 May 2024 14:25:52 -0700 Subject: [PATCH 1/2] Add clusterfuzzlite workflow Signed-off-by: David Korczynski --- .clusterfuzzlite/Dockerfile | 8 ++++++++ .clusterfuzzlite/build.sh | 9 +++++++++ .clusterfuzzlite/fuzzer.c | 30 ++++++++++++++++++++++++++++++ .clusterfuzzlite/project.yaml | 1 + .github/workflows/cflite_pr.yml | 30 ++++++++++++++++++++++++++++++ 5 files changed, 78 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..21af963 --- /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/tinyexpr +COPY .clusterfuzzlite/build.sh $SRC/build.sh +COPY .clusterfuzzlite/*.cpp $SRC/ +COPY .clusterfuzzlite/*.c $SRC/ +WORKDIR tinyexpr diff --git a/.clusterfuzzlite/build.sh b/.clusterfuzzlite/build.sh new file mode 100644 index 0000000..4f623f2 --- /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/tinyexpr/libfuzz.a -Wl,--allow-multiple-definition -I$SRC/tinyexpr/ -o $OUT/fuzzer diff --git a/.clusterfuzzlite/fuzzer.c b/.clusterfuzzlite/fuzzer.c new file mode 100644 index 0000000..a905116 --- /dev/null +++ b/.clusterfuzzlite/fuzzer.c @@ -0,0 +1,30 @@ +#include +#include +#include +#include + +#include "minctest.h" +#include "tinyexpr.h" + +int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { + if (size == 0) { + return 0; + } + + char *input = (char*)malloc(size + 1); + if (!input) { + return 0; + } + + memcpy(input, data, size); + input[size] = '\0'; + + te_variable vars[] = {{ "x", 0 }}; + int error; + te_expr *result = te_compile(input, vars, 1, &error); + + free(input); + te_free(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 be9e48f75bbd2d1e915b133c6eee3f8e47956397 Mon Sep 17 00:00:00 2001 From: David Korczynski Date: Thu, 9 May 2024 16:10:06 -0700 Subject: [PATCH 2/2] cleanup Signed-off-by: David Korczynski --- .clusterfuzzlite/Dockerfile | 1 - .clusterfuzzlite/build.sh | 10 ++++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.clusterfuzzlite/Dockerfile b/.clusterfuzzlite/Dockerfile index 21af963..bd59bf2 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/tinyexpr COPY .clusterfuzzlite/build.sh $SRC/build.sh -COPY .clusterfuzzlite/*.cpp $SRC/ COPY .clusterfuzzlite/*.c $SRC/ WORKDIR tinyexpr diff --git a/.clusterfuzzlite/build.sh b/.clusterfuzzlite/build.sh index 4f623f2..ff3d04d 100644 --- a/.clusterfuzzlite/build.sh +++ b/.clusterfuzzlite/build.sh @@ -1,9 +1,11 @@ #!/bin/bash -find . -name "*.c" -exec $CC $CFLAGS -I./src -c {} \; -find . -name "*.o" -exec cp {} . \; +for file in "smoke.c tinyexpr.c repl.c benchmark.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/tinyexpr/libfuzz.a -Wl,--allow-multiple-definition -I$SRC/tinyexpr/ -o $OUT/fuzzer +$CC $CFLAGS $LIB_FUZZING_ENGINE $SRC/fuzzer.c \ + -Wl,--whole-archive $SRC/tinyexpr/libfuzz.a -Wl,--allow-multiple-definition \ + -I$SRC/tinyexpr/ -o $OUT/fuzzer