brontide: allocate max message buffer on the stack

This commit is contained in:
Olaoluwa Osuntokun 2017-04-19 16:10:10 -07:00
parent 587300aa80
commit 6f2d3b3cc5
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2

@ -680,11 +680,11 @@ func (b *Machine) ReadMessage(r io.Reader) ([]byte, error) {
// Next, using the length read from the packet header, read the
// encrypted packet itself.
var cipherText [math.MaxUint16 + macSize]byte
pktLen := uint32(binary.BigEndian.Uint16(pktLenBytes)) + macSize
cipherText := make([]byte, pktLen)
if _, err := io.ReadFull(r, cipherText[:]); err != nil {
if _, err := io.ReadFull(r, cipherText[:pktLen]); err != nil {
return nil, err
}
return b.recvCipher.Decrypt(nil, nil, cipherText)
return b.recvCipher.Decrypt(nil, nil, cipherText[:pktLen])
}