Skip to content

Commit

Permalink
Better error detection when TLS message greater than buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeuw committed Mar 5, 2019
1 parent a9d4888 commit 47236a1
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions gqserver/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io"
prand "math/rand"
"net"
"strconv"
"time"
)

Expand Down Expand Up @@ -41,15 +42,15 @@ func ReadTillDrain(conn net.Conn, buffer []byte) (n int, err error) {
}

dataLength := BtoInt(buffer[3:5])
if dataLength > len(buffer) {
err = errors.New("Reading TLS message: message size greater than buffer. message size: " + strconv.Itoa(dataLength))
return
}
left := dataLength
readPtr := 5

conn.SetReadDeadline(time.Now().Add(3 * time.Second))
for left != 0 {
if readPtr > len(buffer) || readPtr+left > len(buffer) {
err = errors.New("Reading TLS message: message size greater than buffer")
return
}
// If left > buffer size (i.e. our message got segmented), the entire MTU is read
// if left = buffer size, the entire buffer is all there left to read
// if left < buffer size (i.e. multiple messages came together),
Expand Down

0 comments on commit 47236a1

Please sign in to comment.