mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-06-26 21:29:58 +00:00
QUIC sniffer: Fix potential slice panic (#3406)
* QUIC sniffer: Fix potential slice panic * Fix type err * Update sniff.go * Add test and fix more * Refine
This commit is contained in:
parent
28f558601f
commit
1f2d76c066
@ -116,6 +116,10 @@ func SniffQUIC(b []byte) (*SniffHeader, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errNotQuic
|
return nil, errNotQuic
|
||||||
}
|
}
|
||||||
|
// packet is impossible to shorter than this
|
||||||
|
if packetLen < 4 {
|
||||||
|
return nil, errNotQuic
|
||||||
|
}
|
||||||
|
|
||||||
hdrLen := len(b) - int(buffer.Len())
|
hdrLen := len(b) - int(buffer.Len())
|
||||||
if len(b) < hdrLen+int(packetLen) {
|
if len(b) < hdrLen+int(packetLen) {
|
||||||
|
@ -239,3 +239,21 @@ func TestSniffQUICComplex(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSniffFakeQUICPacketWithInvalidPacketNumberLength(t *testing.T) {
|
||||||
|
pkt, err := hex.DecodeString("cb00000001081c8c6d5aeb53d54400000090709b8600000000000000000000000000000000")
|
||||||
|
common.Must(err)
|
||||||
|
_, err = quic.SniffQUIC(pkt)
|
||||||
|
if err == nil {
|
||||||
|
t.Error("failed")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSniffFakeQUICPacketWithTooShortData(t *testing.T) {
|
||||||
|
pkt, err := hex.DecodeString("cb00000001081c8c6d5aeb53d54400000090709b86")
|
||||||
|
common.Must(err)
|
||||||
|
_, err = quic.SniffQUIC(pkt)
|
||||||
|
if err == nil {
|
||||||
|
t.Error("failed")
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user