Skip to content

Commit

Permalink
pkg/util: Add ClusterfuzzLite
Browse files Browse the repository at this point in the history
Signed-off-by: AdamKorcz <Adam@adalogics.com>
  • Loading branch information
AdamKorcz committed Jul 25, 2022
1 parent a897fac commit 967d40f
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .clusterfuzzlite/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM gcr.io/oss-fuzz-base/base-builder-go
RUN git clone --depth 1 https://github.com/containrrr/shoutrrr
COPY . $SRC/shoutrrr
WORKDIR $SRC/shoutrrr
COPY ./clusterfuzzlite/build.sh $SRC/
1 change: 1 addition & 0 deletions .clusterfuzzlite/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
compile_go_fuzzer github.com/containrrr/shoutrrr/pkg/util FuzzPartitionMessage fuzz_partition_message
1 change: 1 addition & 0 deletions .clusterfuzzlite/project.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
language: go
33 changes: 33 additions & 0 deletions .github/workflows/cflite_pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: ClusterFuzzLite PR fuzzing
on:
pull_request:
paths:
- '**'
permissions: read-all
jobs:
PR:
runs-on: ubuntu-latest
concurrency:
group: ${{ github.workflow }}-${{ matrix.sanitizer }}-${{ github.ref }}
cancel-in-progress: true
strategy:
fail-fast: false
matrix:
sanitizer:
- address
steps:
- name: Build Fuzzers (${{ matrix.sanitizer }})
id: build
uses: google/clusterfuzzlite/actions/build_fuzzers@v1
with:
language: go
github-token: ${{ secrets.GITHUB_TOKEN }}
sanitizer: ${{ matrix.sanitizer }}
- name: Run Fuzzers (${{ matrix.sanitizer }})
id: run
uses: google/clusterfuzzlite/actions/run_fuzzers@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
fuzz-seconds: 600
mode: 'code-change'
sanitizer: ${{ matrix.sanitizer }}
28 changes: 28 additions & 0 deletions pkg/util/fuzz.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package util

import (
fuzz "github.com/AdaLogics/go-fuzz-headers"
t "github.com/containrrr/shoutrrr/pkg/types"
)

func FuzzPartitionMessage(data []byte) int {
f := fuzz.NewConsumer(data)

input, err := f.GetString()
if err != nil {
return 0
}

limits := t.MessageLimit{}
err = f.GenerateStruct(&limits)
if err != nil {
return 0
}

distance, err := f.GetInt()
if err != nil {
return 0
}
_, _ = PartitionMessage(input, limits, distance)
return 1
}

0 comments on commit 967d40f

Please sign in to comment.