Skip to content

Commit

Permalink
connection: fix svacer issue
Browse files Browse the repository at this point in the history
Changed type of 'length' variable in 'read' function to avoid overflow when calculating it.

(cherry picked from 7d73f6a)
  • Loading branch information
better0fdead authored and oleg-jukovec committed Jan 11, 2024
1 parent 1e17e15 commit b500bcd
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -1190,7 +1190,7 @@ func (conn *Connection) timeouts() {
}

func read(r io.Reader, lenbuf []byte) (response []byte, err error) {
var length int
var length uint64

if _, err = io.ReadFull(r, lenbuf); err != nil {
return
Expand All @@ -1199,15 +1199,20 @@ func read(r io.Reader, lenbuf []byte) (response []byte, err error) {
err = errors.New("Wrong response header")
return
}
length = (int(lenbuf[1]) << 24) +
(int(lenbuf[2]) << 16) +
(int(lenbuf[3]) << 8) +
int(lenbuf[4])
length = (uint64(lenbuf[1]) << 24) +
(uint64(lenbuf[2]) << 16) +
(uint64(lenbuf[3]) << 8) +
uint64(lenbuf[4])

if length == 0 {
err = errors.New("Response should not be 0 length")
switch {
case length == 0:
err = errors.New("response should not be 0 length")
return
case length > math.MaxUint32:
err = errors.New("response is too big")
return
}

response = make([]byte, length)
_, err = io.ReadFull(r, response)

Expand Down

0 comments on commit b500bcd

Please sign in to comment.