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))