Skip to content

Commit ef1c165

Browse files
authored
QUIC sniffer: Fix potential slice panic (#4732)
Fixes #3914 (comment)
1 parent bb0e561 commit ef1c165

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

common/protocol/quic/sniff.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ func SniffQUIC(b []byte) (*SniffHeader, error) {
114114
if err != nil {
115115
return nil, errNotQuic
116116
}
117+
// packetLen is impossible to be shorter than this
118+
if packetLen < 4 {
119+
return nil, errNotQuic
120+
}
117121

118122
hdrLen := len(b) - int(buffer.Len())
119123
if len(b) < hdrLen+int(packetLen) {

common/protocol/quic/sniff_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,3 +267,21 @@ func TestSniffQUICPacketNumberLength4(t *testing.T) {
267267
t.Error("failed")
268268
}
269269
}
270+
271+
func TestSniffFakeQUICPacketWithInvalidPacketNumberLength(t *testing.T) {
272+
pkt, err := hex.DecodeString("cb00000001081c8c6d5aeb53d54400000090709b8600000000000000000000000000000000")
273+
common.Must(err)
274+
_, err = quic.SniffQUIC(pkt)
275+
if err == nil {
276+
t.Error("failed")
277+
}
278+
}
279+
280+
func TestSniffFakeQUICPacketWithTooShortData(t *testing.T) {
281+
pkt, err := hex.DecodeString("cb00000001081c8c6d5aeb53d54400000090709b86")
282+
common.Must(err)
283+
_, err = quic.SniffQUIC(pkt)
284+
if err == nil {
285+
t.Error("failed")
286+
}
287+
}

0 commit comments

Comments
 (0)