forked from quic-go/quic-go
use fuzzing helper functions to generate transport parameter seed corpus
This commit is contained in:
@@ -1,14 +1,15 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"bytes"
|
||||
"log"
|
||||
"math"
|
||||
"math/rand"
|
||||
"net"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/lucas-clemente/quic-go/fuzzing/internal/helper"
|
||||
"github.com/lucas-clemente/quic-go/fuzzing/transportparameters"
|
||||
"github.com/lucas-clemente/quic-go/internal/protocol"
|
||||
|
||||
"github.com/lucas-clemente/quic-go/internal/wire"
|
||||
@@ -26,8 +27,7 @@ func getRandomValue() uint64 {
|
||||
}
|
||||
|
||||
func main() {
|
||||
rand.Seed(1337)
|
||||
for i := 0; i < 20; i++ {
|
||||
for i := 0; i < 30; i++ {
|
||||
tp := &wire.TransportParameters{
|
||||
InitialMaxStreamDataBidiLocal: protocol.ByteCount(getRandomValue()),
|
||||
InitialMaxStreamDataBidiRemote: protocol.ByteCount(getRandomValue()),
|
||||
@@ -69,24 +69,21 @@ func main() {
|
||||
StatelessResetToken: token,
|
||||
}
|
||||
}
|
||||
pers := protocol.PerspectiveServer
|
||||
|
||||
var data []byte
|
||||
if rand.Int()%2 == 0 {
|
||||
pers = protocol.PerspectiveClient
|
||||
pers := protocol.PerspectiveServer
|
||||
if rand.Int()%2 == 0 {
|
||||
pers = protocol.PerspectiveClient
|
||||
}
|
||||
data = tp.Marshal(pers)
|
||||
} else {
|
||||
b := &bytes.Buffer{}
|
||||
tp.MarshalForSessionTicket(b)
|
||||
data = b.Bytes()
|
||||
}
|
||||
if err := writeCorpusFile(fmt.Sprintf("tp%d", i), tp.Marshal(pers)); err != nil {
|
||||
if err := helper.WriteCorpusFileWithPrefix("corpus", data, transportparameters.PrefixLen); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func writeCorpusFile(name string, data []byte) error {
|
||||
file, err := os.Create("corpus/" + name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
data = append(getRandomData(2), data...)
|
||||
if _, err := file.Write(data); err != nil {
|
||||
return err
|
||||
}
|
||||
return file.Close()
|
||||
}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -4,28 +4,32 @@ import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
|
||||
"github.com/lucas-clemente/quic-go/fuzzing/internal/helper"
|
||||
"github.com/lucas-clemente/quic-go/internal/protocol"
|
||||
"github.com/lucas-clemente/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) <= 1 {
|
||||
if len(data) <= PrefixLen {
|
||||
return 0
|
||||
}
|
||||
|
||||
if data[0]%2 == 0 {
|
||||
return fuzzTransportParametersForSessionTicket(data[1:])
|
||||
if helper.NthBit(data[0], 0) {
|
||||
return fuzzTransportParametersForSessionTicket(data[PrefixLen:])
|
||||
}
|
||||
return fuzzTransportParameters(data[1:])
|
||||
return fuzzTransportParameters(data[PrefixLen:], helper.NthBit(data[0], 1))
|
||||
}
|
||||
|
||||
func fuzzTransportParameters(data []byte) int {
|
||||
perspective := protocol.PerspectiveServer
|
||||
if data[0]%2 == 1 {
|
||||
func fuzzTransportParameters(data []byte, isServer bool) int {
|
||||
perspective := protocol.PerspectiveClient
|
||||
if isServer {
|
||||
perspective = protocol.PerspectiveServer
|
||||
}
|
||||
data = data[1:]
|
||||
|
||||
tp := &wire.TransportParameters{}
|
||||
if err := tp.Unmarshal(data, perspective); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user