use io.ReadFull instead of Read to read into known length slices

This commit is contained in:
Marten Seemann
2017-08-04 19:34:30 +07:00
parent 2b04d25a55
commit f535cc40de
2 changed files with 4 additions and 8 deletions

View File

@@ -3,6 +3,7 @@ package frames
import (
"bytes"
"errors"
"io"
"github.com/lucas-clemente/quic-go/internal/utils"
"github.com/lucas-clemente/quic-go/protocol"
@@ -70,11 +71,7 @@ func ParseStreamFrame(r *bytes.Reader) (*StreamFrame, error) {
}
if dataLen != 0 {
frame.Data = make([]byte, dataLen)
n, err := r.Read(frame.Data)
if n != int(dataLen) {
return nil, errors.New("BUG: StreamFrame could not read dataLen bytes")
}
if err != nil {
if _, err := io.ReadFull(r, frame.Data); err != nil {
return nil, err
}
}

View File

@@ -3,6 +3,7 @@ package quic
import (
"bytes"
"errors"
"io"
"github.com/lucas-clemente/quic-go/internal/utils"
"github.com/lucas-clemente/quic-go/protocol"
@@ -166,9 +167,7 @@ func ParsePublicHeader(b *bytes.Reader, packetSentBy protocol.Perspective) (*Pub
// see https://github.com/lucas-clemente/quic-go/issues/232
if !header.VersionFlag && !header.ResetFlag {
header.DiversificationNonce = make([]byte, 32)
// this Read can never return an EOF for a valid packet, since the diversification nonce is followed by the packet number
_, err = b.Read(header.DiversificationNonce)
if err != nil {
if _, err := io.ReadFull(b, header.DiversificationNonce); err != nil {
return nil, err
}
}