Skip to content

Commit 1ffb8a9

Browse files
FanglidingRPRX
andauthored
Sniff: Prevent crash on QUIC sniffer panic (#3978)
Co-authored-by: RPRX <[email protected]>
1 parent 4807484 commit 1ffb8a9

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

common/protocol/quic/sniff.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package quic
22

33
import (
4+
"context"
45
"crypto"
56
"crypto/aes"
67
"crypto/tls"
@@ -46,7 +47,18 @@ var (
4647
errNotQuicInitial = errors.New("not initial packet")
4748
)
4849

49-
func SniffQUIC(b []byte) (*SniffHeader, error) {
50+
func SniffQUIC(b []byte) (resultReturn *SniffHeader, errorReturn error) {
51+
// In extremely rare cases, this sniffer may cause slice error
52+
// and we set recover() here to prevent crash.
53+
// TODO: Thoroughly fix this panic
54+
defer func() {
55+
if r := recover(); r != nil {
56+
errors.LogError(context.Background(), "Failed to sniff QUIC: ", r)
57+
resultReturn = nil
58+
errorReturn = common.ErrNoClue
59+
}
60+
}()
61+
5062
// Crypto data separated across packets
5163
cryptoLen := 0
5264
cryptoData := bytespool.Alloc(int32(len(b)))

0 commit comments

Comments
 (0)