Skip to content

Commit 92cf812

Browse files
authored
improve fuzz tests (#592)
1 parent e2d1e6d commit 92cf812

30 files changed

+144
-41
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/bluenviron/gortsplib/v4
33
go 1.20
44

55
require (
6-
github.com/bluenviron/mediacommon v1.12.1
6+
github.com/bluenviron/mediacommon v1.12.2-0.20240801134301-b013c7a52029
77
github.com/google/uuid v1.6.0
88
github.com/pion/rtcp v1.2.14
99
github.com/pion/rtp v1.8.7-0.20240429002300-bc5124c9d0d0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ github.com/asticode/go-astikit v0.30.0 h1:DkBkRQRIxYcknlaU7W7ksNfn4gMFsB0tqMJflx
22
github.com/asticode/go-astikit v0.30.0/go.mod h1:h4ly7idim1tNhaVkdVBeXQZEE3L0xblP7fCWbgwipF0=
33
github.com/asticode/go-astits v1.13.0 h1:XOgkaadfZODnyZRR5Y0/DWkA9vrkLLPLeeOvDwfKZ1c=
44
github.com/asticode/go-astits v1.13.0/go.mod h1:QSHmknZ51pf6KJdHKZHJTLlMegIrhega3LPWz3ND/iI=
5-
github.com/bluenviron/mediacommon v1.12.1 h1:sgDJaKV6OXrPCSO0KPp9zi/pwNWtKHenn5/dvjtY+Tg=
6-
github.com/bluenviron/mediacommon v1.12.1/go.mod h1:HDyW2CzjvhYJXtdxstdFPio3G0qSocPhqkhUt/qffec=
5+
github.com/bluenviron/mediacommon v1.12.2-0.20240801134301-b013c7a52029 h1:s9PNLf98P0uRiBqvY6qKrO1pssPZVCVhs17aSNfXuLY=
6+
github.com/bluenviron/mediacommon v1.12.2-0.20240801134301-b013c7a52029/go.mod h1:HDyW2CzjvhYJXtdxstdFPio3G0qSocPhqkhUt/qffec=
77
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
88
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
99
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=

pkg/auth/sender_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ func FuzzSender(f *testing.F) {
104104
}
105105

106106
f.Fuzz(func(_ *testing.T, a string) {
107-
NewSender(base.HeaderValue{a}, "myuser", "mypass") //nolint:errcheck
107+
se, err := NewSender(base.HeaderValue{a}, "myuser", "mypass")
108+
if err == nil {
109+
se.AddAuthorization(&base.Request{
110+
Method: base.Setup,
111+
URL: mustParseURL("rtsp://myhost/mypath?key=val/trackID=3"),
112+
})
113+
}
108114
})
109115
}

pkg/base/body_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,13 @@ func FuzzBodyUnmarshal(f *testing.F) {
4949

5050
f.Fuzz(func(_ *testing.T, a string, b []byte) {
5151
var p body
52-
p.unmarshal( //nolint:errcheck
52+
err := p.unmarshal(
5353
Header{
5454
"Content-Length": HeaderValue{a},
5555
},
5656
bufio.NewReader(bytes.NewReader(b)))
57+
if err == nil {
58+
p.marshal()
59+
}
5760
})
5861
}

pkg/base/header_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ func FuzzHeaderUnmarshal(f *testing.F) {
138138

139139
f.Fuzz(func(_ *testing.T, b []byte) {
140140
var h Header
141-
h.unmarshal(bufio.NewReader(bytes.NewBuffer(b))) //nolint:errcheck
141+
err := h.unmarshal(bufio.NewReader(bytes.NewBuffer(b)))
142+
if err == nil {
143+
h.marshal()
144+
}
142145
})
143146
}

pkg/base/interleaved_frame_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ func FuzzInterleavedFrameUnmarshal(f *testing.F) {
6060
}
6161
f.Fuzz(func(_ *testing.T, b []byte) {
6262
var f InterleavedFrame
63-
f.Unmarshal(bufio.NewReader(bytes.NewBuffer(b))) //nolint:errcheck
63+
err := f.Unmarshal(bufio.NewReader(bytes.NewBuffer(b)))
64+
if err == nil {
65+
f.Marshal() //nolint:errcheck
66+
}
6467
})
6568
}

pkg/base/request_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,9 @@ func FuzzRequestUnmarshal(f *testing.F) {
188188

189189
f.Fuzz(func(_ *testing.T, b []byte) {
190190
var req Request
191-
req.Unmarshal(bufio.NewReader(bytes.NewBuffer(b))) //nolint:errcheck
191+
err := req.Unmarshal(bufio.NewReader(bytes.NewBuffer(b)))
192+
if err == nil {
193+
req.Marshal() //nolint:errcheck
194+
}
192195
})
193196
}

pkg/base/response_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ func FuzzResponseUnmarshal(f *testing.F) {
162162

163163
f.Fuzz(func(_ *testing.T, b []byte) {
164164
var res Response
165-
res.Unmarshal(bufio.NewReader(bytes.NewBuffer(b))) //nolint:errcheck
165+
err := res.Unmarshal(bufio.NewReader(bytes.NewBuffer(b)))
166+
if err == nil {
167+
res.Marshal() //nolint:errcheck
168+
}
166169
})
167170
}

pkg/description/session_test.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@ func TestSessionFindFormat(t *testing.T) {
837837
require.Equal(t, tr, forma)
838838
}
839839

840-
func FuzzSessionUnmarshalErrors(f *testing.F) {
840+
func FuzzSessionUnmarshal(f *testing.F) {
841841
for _, ca := range casesSession {
842842
f.Add(ca.in)
843843
}
@@ -898,11 +898,9 @@ func FuzzSessionUnmarshalErrors(f *testing.F) {
898898
f.Fuzz(func(_ *testing.T, enc string) {
899899
var sd sdp.SessionDescription
900900
err := sd.Unmarshal([]byte(enc))
901-
if err != nil {
902-
return
901+
if err == nil {
902+
var desc Session
903+
desc.Unmarshal(&sd) //nolint:errcheck
903904
}
904-
905-
var desc Session
906-
desc.Unmarshal(&sd) //nolint:errcheck
907905
})
908906
}

pkg/description/testdata/fuzz/FuzzSessionUnmarshalErrors/b0432aab46b15405 renamed to pkg/description/testdata/fuzz/FuzzSessionUnmarshal/b0432aab46b15405

File renamed without changes.

0 commit comments

Comments
 (0)