From 91b83edf9ca1524ac096fd6e050482ecbfe0e7b1 Mon Sep 17 00:00:00 2001 From: Mikkel Krautz Date: Mon, 11 Apr 2011 21:14:47 +0200 Subject: [PATCH] Make sure to always read full messages. --- client.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/client.go b/client.go index 71af537..71cc3b1 100644 --- a/client.go +++ b/client.go @@ -13,6 +13,7 @@ import ( "goprotobuf.googlecode.com/hg/proto" "mumbleproto" "cryptstate" + "io" "packetdatastream" ) @@ -176,8 +177,10 @@ func (client *Client) RejectAuth(kind, reason string) { // Read a protobuf message from a client func (client *Client) readProtoMessage() (msg *Message, err os.Error) { - var length uint32 - var kind uint16 + var ( + length uint32 + kind uint16 + ) // Read the message type (16-bit big-endian unsigned integer) err = binary.Read(client.reader, binary.BigEndian, &kind) @@ -194,7 +197,7 @@ func (client *Client) readProtoMessage() (msg *Message, err os.Error) { } buf := make([]byte, length) - _, err = client.reader.Read(buf) + _, err = io.ReadFull(client.reader, buf) if err != nil { client.Panic("Unable to read packet content") return