Skip to content

Commit

Permalink
bug: fix Conn.Next not safe (#648)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongweikang committed Nov 6, 2024
1 parent fa3246e commit 8e96be7
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
3 changes: 1 addition & 2 deletions connection_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,11 +326,10 @@ func (c *conn) Next(n int) (buf []byte, err error) {
head, tail := c.inboundBuffer.Peek(n)
defer c.inboundBuffer.Discard(n) //nolint:errcheck
c.loop.cache.Reset()
c.loop.cache.Write(head)
if len(head) >= n {
c.loop.cache.Write(head)
return c.loop.cache.Bytes(), err
}

Check warning on line 332 in connection_unix.go

View check run for this annotation

Codecov / codecov/patch

connection_unix.go#L330-L332

Added lines #L330 - L332 were not covered by tests
c.loop.cache.Write(head)
c.loop.cache.Write(tail)
if inBufferLen >= n {
return c.loop.cache.Bytes(), err
Expand Down
3 changes: 1 addition & 2 deletions connection_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,10 @@ func (c *conn) Next(n int) (buf []byte, err error) {
head, tail := c.inboundBuffer.Peek(n)
defer c.inboundBuffer.Discard(n) //nolint:errcheck
c.loop.cache.Reset()
c.loop.cache.Write(head)
if len(head) >= n {
c.loop.cache.Write(head)
return c.loop.cache.Bytes(), err
}

Check warning on line 171 in connection_windows.go

View check run for this annotation

Codecov / codecov/patch

connection_windows.go#L169-L171

Added lines #L169 - L171 were not covered by tests
c.loop.cache.Write(head)
c.loop.cache.Write(tail)
if inBufferLen >= n {
return c.loop.cache.Bytes(), err
Expand Down

0 comments on commit 8e96be7

Please sign in to comment.