Skip to content

Commit 3146f5b

Browse files
committed
add fuzz test for (signature) decoding
1 parent 582a427 commit 3146f5b

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

proto_fuzz_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//go:build go1.18
2+
// +build go1.18
3+
4+
package dbus
5+
6+
import (
7+
"bytes"
8+
"encoding/binary"
9+
"testing"
10+
)
11+
12+
func FuzzProto(f *testing.F) {
13+
for _, t := range protoTests {
14+
f.Add(t.bigEndian, SignatureOf(t.vs...).str)
15+
f.Add(t.littleEndian, SignatureOf(t.vs...).str)
16+
}
17+
f.Fuzz(func(t *testing.T, buf []byte, sigStr string) {
18+
sig, err := ParseSignature(sigStr)
19+
if err != nil {
20+
return
21+
}
22+
bigDec := newDecoder(bytes.NewReader(buf), binary.BigEndian, make([]int, 0))
23+
_, _ = bigDec.Decode(sig)
24+
})
25+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
go test fuzz v1
2+
[]byte("0")
3+
string("a{}")

0 commit comments

Comments
 (0)