chore: Add early bounds checks

This commit is contained in:
gVisor bot 2023-04-05 13:51:50 +08:00
parent c0bcf77bf7
commit 8358114e31
2 changed files with 2 additions and 0 deletions

View file

@ -147,6 +147,7 @@ func (g *Conn) WriteBuffer(buffer *buf.Buffer) error {
dataLen := buffer.Len() dataLen := buffer.Len()
varLen := UVarintLen(uint64(dataLen)) varLen := UVarintLen(uint64(dataLen))
header := buffer.ExtendHeader(6 + varLen) header := buffer.ExtendHeader(6 + varLen)
_ = header[6] // bounds check hint to compiler
header[0] = 0x00 header[0] = 0x00
binary.BigEndian.PutUint32(header[1:5], uint32(1+varLen+dataLen)) binary.BigEndian.PutUint32(header[1:5], uint32(1+varLen+dataLen))
header[5] = 0x0A header[5] = 0x0A

View file

@ -107,6 +107,7 @@ func (wsc *websocketConn) WriteBuffer(buffer *buf.Buffer) error {
headerLen += 4 // MASK KEY headerLen += 4 // MASK KEY
header := buffer.ExtendHeader(headerLen) header := buffer.ExtendHeader(headerLen)
_ = header[2] // bounds check hint to compiler
header[0] = websocket.BinaryMessage | 1<<7 header[0] = websocket.BinaryMessage | 1<<7
header[1] = 1 << 7 header[1] = 1 << 7