Skip to content

Commit 53c5234

Browse files
committed
add: new go-fuzz targets
Signed-off-by: Arjun <[email protected]>
1 parent 1f3e304 commit 53c5234

File tree

5 files changed

+67
-0
lines changed

5 files changed

+67
-0
lines changed

Makefile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,18 @@ cover:
165165
# Generate the HTML report that can be viewed from the browser in CI.
166166
$Q go tool cover -html ".cover/c.out" -o .cover/all.html
167167

168+
.PHONY: fuzz
169+
fuzz:
170+
@go test -fuzz=FuzzIPDecoder -fuzztime=600s ./packet
171+
@go test -fuzz=FuzzICMPDecoder -fuzztime=600s ./packet
172+
@go test -fuzz=FuzzSessionWrite -fuzztime=600s ./quic/v3
173+
@go test -fuzz=FuzzSessionServe -fuzztime=600s ./quic/v3
174+
@go test -fuzz=FuzzRegistrationDatagram -fuzztime=600s ./quic/v3
175+
@go test -fuzz=FuzzPayloadDatagram -fuzztime=600s ./quic/v3
176+
@go test -fuzz=FuzzRegistrationResponseDatagram -fuzztime=600s ./quic/v3
177+
@go test -fuzz=FuzzNewIdentity -fuzztime=600s ./tracing
178+
@go test -fuzz=FuzzNewAccessValidator -fuzztime=600s ./validation
179+
168180
.PHONY: install-go
169181
install-go:
170182
rm -rf ${CF_GO_PATH}

packet/decoder_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,3 +254,18 @@ func (u *UDP) EncodeLayers() ([]gopacket.SerializableLayer, error) {
254254
udpLayer.SetNetworkLayerForChecksum(ipLayers[0].(gopacket.NetworkLayer))
255255
return append(ipLayers, &udpLayer), nil
256256
}
257+
258+
func FuzzIPDecoder(f *testing.F) {
259+
f.Fuzz(func(t *testing.T, data []byte) {
260+
ipDecoder := NewIPDecoder()
261+
ipDecoder.Decode(RawPacket{Data: data})
262+
263+
})
264+
}
265+
266+
func FuzzICMPDecoder(f *testing.F) {
267+
f.Fuzz(func(t *testing.T, data []byte) {
268+
icmpDecoder := NewICMPDecoder()
269+
icmpDecoder.Decode(RawPacket{Data: data})
270+
})
271+
}

quic/v3/datagram_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,3 +350,30 @@ func compareRegistrationDatagrams(t *testing.T, l *v3.UDPSessionRegistrationData
350350
l.IdleDurationHint == r.IdleDurationHint &&
351351
l.Traced == r.Traced
352352
}
353+
354+
func FuzzRegistrationDatagram(f *testing.F) {
355+
f.Fuzz(func(t *testing.T, data []byte) {
356+
unmarshaled := v3.UDPSessionRegistrationDatagram{}
357+
err := unmarshaled.UnmarshalBinary(data)
358+
if err == nil {
359+
_, _ = unmarshaled.MarshalBinary()
360+
}
361+
})
362+
}
363+
364+
func FuzzPayloadDatagram(f *testing.F) {
365+
f.Fuzz(func(t *testing.T, data []byte) {
366+
unmarshaled := v3.UDPSessionPayloadDatagram{}
367+
_ = unmarshaled.UnmarshalBinary(data)
368+
})
369+
}
370+
371+
func FuzzRegistrationResponseDatagram(f *testing.F) {
372+
f.Fuzz(func(t *testing.T, data []byte) {
373+
unmarshaled := v3.UDPSessionRegistrationResponseDatagram{}
374+
err := unmarshaled.UnmarshalBinary(data)
375+
if err == nil {
376+
_, _ = unmarshaled.MarshalBinary()
377+
}
378+
})
379+
}

tracing/tracing_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,9 @@ func TestAddingSpansWithNilMap(t *testing.T) {
7272
// a panic shouldn't occur
7373
tr.AddSpans(nil)
7474
}
75+
76+
func FuzzNewIdentity(f *testing.F) {
77+
f.Fuzz(func(t *testing.T, trace string) {
78+
_, _ = NewIdentity(trace)
79+
})
80+
}

validation/validation_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,3 +197,10 @@ func createSecureMockServerAndClient(handler http.Handler) (*httptest.Server, *h
197197

198198
return server, client, nil
199199
}
200+
201+
func FuzzNewAccessValidator(f *testing.F) {
202+
f.Fuzz(func(t *testing.T, domain string, issuer string, applicationAUD string) {
203+
ctx := context.Background()
204+
_, _ = NewAccessValidator(ctx, domain, issuer, applicationAUD)
205+
})
206+
}

0 commit comments

Comments
 (0)