From c12abea09a293d62fc2762567beb9b90bd617721 Mon Sep 17 00:00:00 2001 From: Raj Shah Date: Sun, 28 May 2023 17:42:52 +0000 Subject: [PATCH 1/2] Add harness --- .github/workflows/mayhem.yml | 78 +++++++++++++++++++++++++++++++++ mayhem/Dockerfile | 18 ++++++++ mayhem/Mayhemfile_to_lower_copy | 5 +++ mayhem/fuzz_to_lower_copy.cpp | 17 +++++++ 4 files changed, 118 insertions(+) create mode 100644 .github/workflows/mayhem.yml create mode 100644 mayhem/Dockerfile create mode 100644 mayhem/Mayhemfile_to_lower_copy create mode 100644 mayhem/fuzz_to_lower_copy.cpp diff --git a/.github/workflows/mayhem.yml b/.github/workflows/mayhem.yml new file mode 100644 index 00000000..d3bec584 --- /dev/null +++ b/.github/workflows/mayhem.yml @@ -0,0 +1,78 @@ +name: Mayhem +permissions: write-all +on: + push: + pull_request: + workflow_dispatch: + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build: + name: '${{ matrix.os }} shared=${{ matrix.shared }} ${{ matrix.build_type }}' + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest] + shared: [false] + build_type: [Release] + include: + - os: ubuntu-latest + triplet: x64-linux + + steps: + - uses: actions/checkout@v3 + with: + submodules: recursive + + - name: Log in to the Container registry + uses: docker/login-action@v2.1.0 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v4.1.1 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + - name: Build and push Docker image + uses: docker/build-push-action@v3.2.0 + with: + context: . + push: true + file: mayhem/Dockerfile + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + + outputs: + image: ${{ steps.meta.outputs.tags }} + + mayhem: + needs: build + name: 'fuzz ${{ matrix.mayhemfile }}' + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + mayhemfile: + - mayhem/Mayhemfile_to_lower_copy + + steps: + - uses: actions/checkout@v3 + + - name: Start analysis for ${{ matrix.mayhemfile }} + uses: ForAllSecure/mcode-action@v1 + with: + mayhem-token: ${{ secrets.MAYHEM_TOKEN }} + args: --image ${{ needs.build.outputs.image }} --file ${{ matrix.mayhemfile }} --duration 300 + sarif-output: sarif + + - name: Upload SARIF file(s) + uses: github/codeql-action/upload-sarif@v2 + with: + sarif_file: sarif diff --git a/mayhem/Dockerfile b/mayhem/Dockerfile new file mode 100644 index 00000000..52b3b7dc --- /dev/null +++ b/mayhem/Dockerfile @@ -0,0 +1,18 @@ +FROM --platform=linux/amd64 ubuntu:22.04 as builder + +RUN apt-get update +RUN DEBIAN_FRONTEND=noninteractive apt-get install -y build-essential clang libmicrohttpd-dev automake pkg-config libtool + +COPY . /repo +WORKDIR /repo +RUN ./bootstrap +WORKDIR /repo/build +RUN ../configure --prefix=/install +RUN make -j8 +RUN make install + +RUN clang++ /repo/mayhem/fuzz_to_lower_copy.cpp -fsanitize=fuzzer,address -std=c++17 -I /repo/src/ /install/lib/libhttpserver.a -o /fuzz_to_lower_copy + +FROM ubuntu:22.04 as package + +COPY --from=builder /fuzz /fuzz_to_lower_copy diff --git a/mayhem/Mayhemfile_to_lower_copy b/mayhem/Mayhemfile_to_lower_copy new file mode 100644 index 00000000..cbdc55d1 --- /dev/null +++ b/mayhem/Mayhemfile_to_lower_copy @@ -0,0 +1,5 @@ +project: libhttpserver +target: to-lower-copy +cmds: + - cmd: /fuzz_to_lower_copy + libfuzzer: true diff --git a/mayhem/fuzz_to_lower_copy.cpp b/mayhem/fuzz_to_lower_copy.cpp new file mode 100644 index 00000000..0c88d022 --- /dev/null +++ b/mayhem/fuzz_to_lower_copy.cpp @@ -0,0 +1,17 @@ +#include +#include + +#define _HTTPSERVER_HPP_INSIDE_ 1 + +#include +#include "httpserver/string_utilities.hpp" + + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + FuzzedDataProvider provider(data, size); + std::string str = provider.ConsumeRandomLengthString(); + httpserver::string_utilities::to_lower_copy(str); + + return 0; +} From ded34e6a054e5b1753d6477c5d3ee69d8f6388a2 Mon Sep 17 00:00:00 2001 From: Raj Shah Date: Sun, 28 May 2023 17:49:38 +0000 Subject: [PATCH 2/2] Fix typo --- mayhem/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mayhem/Dockerfile b/mayhem/Dockerfile index 52b3b7dc..68f4c09c 100644 --- a/mayhem/Dockerfile +++ b/mayhem/Dockerfile @@ -11,7 +11,7 @@ RUN ../configure --prefix=/install RUN make -j8 RUN make install -RUN clang++ /repo/mayhem/fuzz_to_lower_copy.cpp -fsanitize=fuzzer,address -std=c++17 -I /repo/src/ /install/lib/libhttpserver.a -o /fuzz_to_lower_copy +RUN clang++ /repo/mayhem/fuzz_to_lower_copy.cpp -fsanitize=fuzzer,address -std=c++17 -I /repo/src/ /install/lib/libhttpserver.a -o /fuzz FROM ubuntu:22.04 as package