Skip to content

Commit 2ea4f87

Browse files
committed
fix nil buffer panic for tls reading
1 parent e70b385 commit 2ea4f87

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

std/crypto/tls/conn.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -967,14 +967,22 @@ func (c *Conn) readFromUntil(r io.Reader, n int, from int) error {
967967
// c.rawInputOff = 0
968968
// }
969969

970-
needs := from + n - cap(*c.rawInput)
970+
needs := from + n
971+
if c.rawInput == nil {
972+
c.rawInput = c.allocator.Malloc(needs)
973+
needs = 0
974+
} else {
975+
needs -= cap(*c.rawInput)
976+
}
977+
971978
// There might be extra input waiting on the wire. Make a best effort
972979
// attempt to fetch it so that it can be used in (*Conn).Read to
973980
// "predict" closeNotify alerts.
974981
if needs > 0 {
975982
*c.rawInput = (*c.rawInput)[:cap(*c.rawInput)]
976983
c.rawInput = c.allocator.Append(c.rawInput, make([]byte, needs)...)
977984
}
985+
978986
*c.rawInput = (*c.rawInput)[:from+n]
979987
_, err := io.ReadFull(r, (*c.rawInput)[from:])
980988
return err

0 commit comments

Comments
 (0)