mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-03-26 08:55:59 +01:00
lnwire: use ReadFull instead of Read when parsing feature vectors
This commit fixes a bug lingering in the decoding of the feature vectors which was masked by the prior method of reading the _entire_ message from the stream before parsing it. The issue was that performing a zero-byte Read on an io.Reader that’s purely streaming will result in an indefinite block. We fix this bug by properly using io.ReadFull in this context.
This commit is contained in:
parent
9324a503c9
commit
587300aa80
1 changed files with 2 additions and 2 deletions
|
@ -136,14 +136,14 @@ func NewFeatureVectorFromReader(r io.Reader) (*FeatureVector, error) {
|
|||
|
||||
// Read the length of the feature vector.
|
||||
var l [2]byte
|
||||
if _, err := r.Read(l[:]); err != nil {
|
||||
if _, err := io.ReadFull(r, l[:]); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
length := binary.BigEndian.Uint16(l[:])
|
||||
|
||||
// Read the feature vector data.
|
||||
data := make([]byte, length)
|
||||
if _, err := r.Read(data); err != nil {
|
||||
if _, err := io.ReadFull(r, data[:]); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue