parse arbitrary length Connection IDs in Version Negotiation packets

This commit is contained in:
Marten Seemann 2022-08-28 14:34:23 +03:00
parent 53412e9ba3
commit 9e0f9e62ff
9 changed files with 116 additions and 100 deletions

View file

@ -19,7 +19,7 @@ func getRandomData(l int) []byte {
return b
}
func getVNP(src, dest protocol.ConnectionID, numVersions int) []byte {
func getVNP(src, dest protocol.ArbitraryLenConnectionID, numVersions int) []byte {
versions := make([]protocol.VersionNumber, numVersions)
for i := 0; i < numVersions; i++ {
versions[i] = protocol.VersionNumber(rand.Uint32())
@ -113,28 +113,28 @@ func main() {
vnps := [][]byte{
getVNP(
protocol.ConnectionID(getRandomData(8)),
protocol.ConnectionID(getRandomData(10)),
protocol.ArbitraryLenConnectionID(getRandomData(8)),
protocol.ArbitraryLenConnectionID(getRandomData(10)),
4,
),
getVNP(
protocol.ConnectionID(getRandomData(10)),
protocol.ConnectionID(getRandomData(5)),
protocol.ArbitraryLenConnectionID(getRandomData(10)),
protocol.ArbitraryLenConnectionID(getRandomData(5)),
0,
),
getVNP(
protocol.ConnectionID(getRandomData(3)),
protocol.ConnectionID(getRandomData(19)),
protocol.ArbitraryLenConnectionID(getRandomData(3)),
protocol.ArbitraryLenConnectionID(getRandomData(19)),
100,
),
getVNP(
protocol.ConnectionID(getRandomData(3)),
protocol.ArbitraryLenConnectionID(getRandomData(3)),
nil,
20,
),
getVNP(
nil,
protocol.ConnectionID(getRandomData(10)),
protocol.ArbitraryLenConnectionID(getRandomData(10)),
5,
),
}

View file

@ -82,16 +82,16 @@ func fuzzVNP(data []byte) int {
if err != nil {
return 0
}
hdr, versions, err := wire.ParseVersionNegotiationPacket(bytes.NewReader(data))
dest, src, versions, err := wire.ParseVersionNegotiationPacket(data)
if err != nil {
return 0
}
if !hdr.DestConnectionID.Equal(connID) {
if !bytes.Equal(dest, connID.Bytes()) {
panic("connection IDs don't match")
}
if len(versions) == 0 {
panic("no versions")
}
wire.ComposeVersionNegotiation(hdr.SrcConnectionID, hdr.DestConnectionID, versions)
wire.ComposeVersionNegotiation(src, dest, versions)
return 1
}