From 9a16b6768effc9e40a3c445ea8d085c7f277e643 Mon Sep 17 00:00:00 2001 From: Mark DeLillo Date: Wed, 26 Apr 2017 12:15:57 -0400 Subject: [PATCH] Fix decode - Write decoded bytes without padding Signed-off-by: Natalie Arellano --- communicator/winrm/communicator.go | 5 +++-- communicator/winrm/communicator_test.go | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/communicator/winrm/communicator.go b/communicator/winrm/communicator.go index 355548715..d1f7d2ab6 100644 --- a/communicator/winrm/communicator.go +++ b/communicator/winrm/communicator.go @@ -203,9 +203,10 @@ func (d *Base64Pipe) ReadFrom(r io.Reader) (int64, error) { func (d *Base64Pipe) Write(p []byte) (int, error) { dst := make([]byte, base64.StdEncoding.DecodedLen(len(p))) - if _, err := base64.StdEncoding.Decode(dst, p); err != nil { + decodedBytes, err := base64.StdEncoding.Decode(dst, p) + if err != nil { return 0, err } - return d.w.Write(dst) + return d.w.Write(dst[0:decodedBytes]) } diff --git a/communicator/winrm/communicator_test.go b/communicator/winrm/communicator_test.go index b80f8316b..d5eb974ac 100644 --- a/communicator/winrm/communicator_test.go +++ b/communicator/winrm/communicator_test.go @@ -108,7 +108,7 @@ func TestUpload(t *testing.T) { if err != nil { t.Fatalf("error downloading file: %s", err) } - downloadedPayload := strings.TrimRight(dest.String(), "\x00") + downloadedPayload := dest.String() if downloadedPayload != PAYLOAD { t.Fatalf("files are not equal: expected [%s] length: %v, got [%s] length %v", PAYLOAD, len(PAYLOAD), downloadedPayload, len(downloadedPayload))