Skip to content

Commit 087626e

Browse files
committed
pkg/util: Add ClusterfuzzLite
Signed-off-by: AdamKorcz <[email protected]>
1 parent a897fac commit 087626e

File tree

5 files changed

+64
-0
lines changed

5 files changed

+64
-0
lines changed

.clusterfuzzlite/Dockerfile

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM gcr.io/oss-fuzz-base/base-builder-go
2+
RUN git clone --depth 1 https://github.com/containrrr/shoutrrr
3+
COPY . $SRC/shoutrrr
4+
WORKDIR $SRC/shoutrrr
5+
COPY ./clusterfuzzlite/build.sh $SRC/

.clusterfuzzlite/build.sh

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
compile_go_fuzzer github.com/containrrr/shoutrrr/pkg/util FuzzPartitionMessage fuzz_partition_message

.clusterfuzzlite/project.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
language: go

.github/workflows/cflite_pr.yml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: ClusterFuzzLite PR fuzzing
2+
on:
3+
workflow_dispatch:
4+
pull_request:
5+
paths:
6+
- '**'
7+
permissions: read-all
8+
jobs:
9+
PR:
10+
runs-on: ubuntu-latest
11+
strategy:
12+
fail-fast: false
13+
matrix:
14+
sanitizer: [address]
15+
steps:
16+
- name: Build Fuzzers (${{ matrix.sanitizer }})
17+
id: build
18+
uses: google/clusterfuzzlite/actions/build_fuzzers@v1
19+
with:
20+
sanitizer: ${{ matrix.sanitizer }}
21+
language: go
22+
- name: Run Fuzzers (${{ matrix.sanitizer }})
23+
id: run
24+
uses: google/clusterfuzzlite/actions/run_fuzzers@v1
25+
with:
26+
github-token: ${{ secrets.GITHUB_TOKEN }}
27+
fuzz-seconds: 400
28+
mode: 'code-change'
29+
sanitizer: ${{ matrix.sanitizer }}

pkg/util/fuzz.go

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package util
2+
3+
import (
4+
fuzz "github.com/AdaLogics/go-fuzz-headers"
5+
t "github.com/containrrr/shoutrrr/pkg/types"
6+
)
7+
8+
func FuzzPartitionMessage(data []byte) int {
9+
f := fuzz.NewConsumer(data)
10+
11+
input, err := f.GetString()
12+
if err != nil {
13+
return 0
14+
}
15+
16+
limits := t.MessageLimit{}
17+
err = f.GenerateStruct(&limits)
18+
if err != nil {
19+
return 0
20+
}
21+
22+
distance, err := f.GetInt()
23+
if err != nil {
24+
return 0
25+
}
26+
_, _ = PartitionMessage(input, limits, distance)
27+
return 1
28+
}

0 commit comments

Comments
 (0)