Skip to content

Commit 56e2dd2

Browse files
committed
fix: improve buffer handling in QUICClientHello
1 parent 1108777 commit 56e2dd2

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

common/sniff/quic.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ func QUICClientHello(ctx context.Context, metadata *adapter.InboundContext, pack
2626
metadata.SniffContext = nil
2727
} else {
2828
ja3DataBuf = buf.NewSize(32 * 1024)
29+
_ = ja3DataBuf.WriteZeroN(5)
2930
}
3031
defer func() {
3132
if ja3DataBuf != nil {
@@ -230,11 +231,11 @@ sniff:
230231

231232
start := int(5 + offset)
232233
end := start + int(length)
233-
if ja3DataBuf.Len() < end {
234-
if ja3DataBuf.Cap() < end {
235-
return io.ErrShortBuffer
234+
// Ensure ja3DataBuf has enough space
235+
if n := end - ja3DataBuf.Len(); n > 0 {
236+
if err := ja3DataBuf.WriteZeroN(n); err != nil {
237+
return err
236238
}
237-
ja3DataBuf.Truncate(end)
238239
}
239240

240241
_, err = decryptedReader.Read(ja3DataBuf.Range(start, end))

0 commit comments

Comments
 (0)