From 5cf868a24ea32b3d89fa06004db9fcb20601f586 Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Thu, 16 Nov 2017 22:29:04 +0000 Subject: [PATCH] fix TCP read --- client/network.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/client/network.go b/client/network.go index 3feb9ce4..68c07e0a 100644 --- a/client/network.go +++ b/client/network.go @@ -6,7 +6,6 @@ import ( "fmt" "gopkg.in/jcmturner/gokrb5.v2/iana/errorcode" "gopkg.in/jcmturner/gokrb5.v2/messages" - "io" "math/rand" "net" "time" @@ -154,10 +153,21 @@ func sendTCP(kdc string, b []byte) ([]byte, error) { if err != nil { return r, fmt.Errorf("Error sending to KDC: %v", err) } - var rBuf bytes.Buffer - io.Copy(&rBuf, conn) - r = rBuf.Bytes() - return checkForKRBError(r[4:]) + + sh := make([]byte, 4, 4) + _, err = conn.Read(sh) + if err != nil { + return r, fmt.Errorf("error reading response size header: %v", err) + } + s := binary.BigEndian.Uint32(sh) + + rb := make([]byte, s, s) + _, err = conn.Read(rb) + if err != nil { + return r, fmt.Errorf("error reading response: %v", err) + } + + return checkForKRBError(rb) } func checkForKRBError(b []byte) ([]byte, error) {