Skip to content

Commit 967d40f

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

File tree

5 files changed

+68
-0
lines changed

5 files changed

+68
-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

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