From 8358114e314fc1862f79bc2f79dcf0c285c4a89a Mon Sep 17 00:00:00 2001 From: gVisor bot Date: Wed, 5 Apr 2023 13:51:50 +0800 Subject: [PATCH] chore: Add early bounds checks --- transport/gun/gun.go | 1 + transport/vmess/websocket.go | 1 + 2 files changed, 2 insertions(+) diff --git a/transport/gun/gun.go b/transport/gun/gun.go index ae2ea6a4..0e5d2321 100644 --- a/transport/gun/gun.go +++ b/transport/gun/gun.go @@ -147,6 +147,7 @@ func (g *Conn) WriteBuffer(buffer *buf.Buffer) error { dataLen := buffer.Len() varLen := UVarintLen(uint64(dataLen)) header := buffer.ExtendHeader(6 + varLen) + _ = header[6] // bounds check hint to compiler header[0] = 0x00 binary.BigEndian.PutUint32(header[1:5], uint32(1+varLen+dataLen)) header[5] = 0x0A diff --git a/transport/vmess/websocket.go b/transport/vmess/websocket.go index 5fcaa0b8..179da886 100644 --- a/transport/vmess/websocket.go +++ b/transport/vmess/websocket.go @@ -107,6 +107,7 @@ func (wsc *websocketConn) WriteBuffer(buffer *buf.Buffer) error { headerLen += 4 // MASK KEY header := buffer.ExtendHeader(headerLen) + _ = header[2] // bounds check hint to compiler header[0] = websocket.BinaryMessage | 1<<7 header[1] = 1 << 7