Skip to content

Commit 986e8d7

Browse files
committed
fix: Protect cache peek
1 parent c7a00e8 commit 986e8d7

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

common/bufio/cached.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package bufio
22

33
import (
44
"bytes"
5+
"fmt"
56
"io"
67
"net"
78

@@ -57,6 +58,9 @@ func (c *CachedConn) Read(p []byte) (n int, err error) {
5758
}
5859

5960
func (c *CachedConn) Peek(n int) ([]byte, error) {
61+
if n < 0 {
62+
return nil, fmt.Errorf("peek with negative size: %d", n)
63+
}
6064
if c.cache == nil {
6165
// see above
6266
c.cache = buf.NewSize(4096)

0 commit comments

Comments
 (0)