forked from apernet/quic-go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
fuzz.go
60 lines (51 loc) · 1.43 KB
/
fuzz.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package transportparameters
import (
"bytes"
"fmt"
"github.com/Yuzuki616/quic-go/fuzzing/internal/helper"
"github.com/Yuzuki616/quic-go/internal/protocol"
"github.com/Yuzuki616/quic-go/internal/wire"
)
// PrefixLen is the number of bytes used for configuration
const PrefixLen = 1
// Fuzz fuzzes the QUIC transport parameters.
//
//go:generate go run ./cmd/corpus.go
func Fuzz(data []byte) int {
if len(data) <= PrefixLen {
return 0
}
if helper.NthBit(data[0], 0) {
return fuzzTransportParametersForSessionTicket(data[PrefixLen:])
}
return fuzzTransportParameters(data[PrefixLen:], helper.NthBit(data[0], 1))
}
func fuzzTransportParameters(data []byte, isServer bool) int {
perspective := protocol.PerspectiveClient
if isServer {
perspective = protocol.PerspectiveServer
}
tp := &wire.TransportParameters{}
if err := tp.Unmarshal(data, perspective); err != nil {
return 0
}
_ = tp.String()
tp2 := &wire.TransportParameters{}
if err := tp2.Unmarshal(tp.Marshal(perspective), perspective); err != nil {
fmt.Printf("%#v\n", tp)
panic(err)
}
return 1
}
func fuzzTransportParametersForSessionTicket(data []byte) int {
tp := &wire.TransportParameters{}
if err := tp.UnmarshalFromSessionTicket(bytes.NewReader(data)); err != nil {
return 0
}
b := tp.MarshalForSessionTicket(nil)
tp2 := &wire.TransportParameters{}
if err := tp2.UnmarshalFromSessionTicket(bytes.NewReader(b)); err != nil {
panic(err)
}
return 1
}