fixes response overwrite bug

This fixes a bug in truncated response payload handling. Payloads
requiring more than one call to `Read()` were overwiting the previous
Read()'s buffer contents. Because we know the response payload size, we
can simply call `io.ReadAll()` rather than looping over calls to
`Read()`.
This commit is contained in:
Ben LeMasurier 2016-06-27 12:40:39 -06:00
parent d57bbc34c4
commit e99de2e999
No known key found for this signature in database
GPG Key ID: 248D430AE8E74189

6
rpc.go
View File

@ -195,16 +195,12 @@ func (l *Libvirt) listen() {
// payload: packet length minus what was previously read // payload: packet length minus what was previously read
size := int(length) - (constants.PacketLengthSize + constants.HeaderSize) size := int(length) - (constants.PacketLengthSize + constants.HeaderSize)
buf := make([]byte, size) buf := make([]byte, size)
for n := 0; n < size; { _, err = io.ReadFull(l.r, buf)
nn, err := l.r.Read(buf)
if err != nil { if err != nil {
// invalid packet // invalid packet
continue continue
} }
n += nn
}
// route response to caller // route response to caller
l.route(h, buf) l.route(h, buf)
} }