forked from quic-go/quic-go
use io.ReadFull instead of Read to read into known length slices
This commit is contained in:
@@ -3,6 +3,7 @@ package frames
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
|
"io"
|
||||||
|
|
||||||
"github.com/lucas-clemente/quic-go/internal/utils"
|
"github.com/lucas-clemente/quic-go/internal/utils"
|
||||||
"github.com/lucas-clemente/quic-go/protocol"
|
"github.com/lucas-clemente/quic-go/protocol"
|
||||||
@@ -70,11 +71,7 @@ func ParseStreamFrame(r *bytes.Reader) (*StreamFrame, error) {
|
|||||||
}
|
}
|
||||||
if dataLen != 0 {
|
if dataLen != 0 {
|
||||||
frame.Data = make([]byte, dataLen)
|
frame.Data = make([]byte, dataLen)
|
||||||
n, err := r.Read(frame.Data)
|
if _, err := io.ReadFull(r, frame.Data); err != nil {
|
||||||
if n != int(dataLen) {
|
|
||||||
return nil, errors.New("BUG: StreamFrame could not read dataLen bytes")
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package quic
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
|
"io"
|
||||||
|
|
||||||
"github.com/lucas-clemente/quic-go/internal/utils"
|
"github.com/lucas-clemente/quic-go/internal/utils"
|
||||||
"github.com/lucas-clemente/quic-go/protocol"
|
"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
|
// see https://github.com/lucas-clemente/quic-go/issues/232
|
||||||
if !header.VersionFlag && !header.ResetFlag {
|
if !header.VersionFlag && !header.ResetFlag {
|
||||||
header.DiversificationNonce = make([]byte, 32)
|
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
|
if _, err := io.ReadFull(b, header.DiversificationNonce); err != nil {
|
||||||
_, err = b.Read(header.DiversificationNonce)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user