From e99de2e999606896eb1dc1ffa6e8984ae3e95468 Mon Sep 17 00:00:00 2001 From: Ben LeMasurier Date: Mon, 27 Jun 2016 12:40:39 -0600 Subject: [PATCH] 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()`. --- rpc.go | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/rpc.go b/rpc.go index c0c1c46..87ea71d 100644 --- a/rpc.go +++ b/rpc.go @@ -195,14 +195,10 @@ func (l *Libvirt) listen() { // payload: packet length minus what was previously read size := int(length) - (constants.PacketLengthSize + constants.HeaderSize) buf := make([]byte, size) - for n := 0; n < size; { - nn, err := l.r.Read(buf) - if err != nil { - // invalid packet - continue - } - - n += nn + _, err = io.ReadFull(l.r, buf) + if err != nil { + // invalid packet + continue } // route response to caller