forked from quic-go/quic-go
don’t panic if the STK doesn’t contain any data
This commit is contained in:
@@ -89,6 +89,10 @@ func encodeRemoteAddr(remoteAddr net.Addr) []byte {
|
|||||||
|
|
||||||
// decodeRemoteAddr decodes the remote address saved in the STK
|
// decodeRemoteAddr decodes the remote address saved in the STK
|
||||||
func decodeRemoteAddr(data []byte) string {
|
func decodeRemoteAddr(data []byte) string {
|
||||||
|
// data will never be empty for an STK that we generated. Check it to be on the safe side
|
||||||
|
if len(data) == 0 {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
if data[0] == stkPrefixIP {
|
if data[0] == stkPrefixIP {
|
||||||
return net.IP(data[1:]).String()
|
return net.IP(data[1:]).String()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,6 +63,16 @@ var _ = Describe("STK Generator", func() {
|
|||||||
Expect(err).To(MatchError("rest when unpacking token: 4"))
|
Expect(err).To(MatchError("rest when unpacking token: 4"))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// we don't generate tokens that have no data, but we should be able to handle them if we receive one for whatever reason
|
||||||
|
It("doesn't panic if a tokens has no data", func() {
|
||||||
|
t, err := asn1.Marshal(token{Data: []byte("")})
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
enc, err := stkGen.stkSource.NewToken(t)
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
_, err = stkGen.DecodeToken(enc)
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
})
|
||||||
|
|
||||||
It("works with an IPv6 addresses ", func() {
|
It("works with an IPv6 addresses ", func() {
|
||||||
addresses := []string{
|
addresses := []string{
|
||||||
"2001:db8::68",
|
"2001:db8::68",
|
||||||
|
|||||||
Reference in New Issue
Block a user