瀏覽代碼

Socks: Fix buffer full panic when encoding large UDP packets (#5252)

Co-authored-by: 风扇滑翔翼 <[email protected]>
vemneyy 6 月之前
父節點
當前提交
b16a5f03fe
共有 1 個文件被更改,包括 5 次插入0 次删除
  1. 5 0
      proxy/socks/protocol.go

+ 5 - 0
proxy/socks/protocol.go

@@ -353,6 +353,11 @@ func EncodeUDPPacket(request *protocol.RequestHeader, data []byte) (*buf.Buffer,
 		b.Release()
 		return nil, err
 	}
+	// if data is too large, return an empty buffer (drop too big data)
+	if b.Available() < int32(len(data)) {
+		b.Clear()
+		return b, nil
+	}
 	common.Must2(b.Write(data))
 	return b, nil
 }