From 5b9adc0c4811d5221f1def0bf30dccb50f977284 Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Thu, 11 Oct 2018 13:57:34 -0700 Subject: [PATCH 1/7] single quotes --- builder/vmware/iso/driver_esx5.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/builder/vmware/iso/driver_esx5.go b/builder/vmware/iso/driver_esx5.go index 300543e22..63b29a021 100644 --- a/builder/vmware/iso/driver_esx5.go +++ b/builder/vmware/iso/driver_esx5.go @@ -51,8 +51,7 @@ func (d *ESX5Driver) CompactDisk(diskPathLocal string) error { } func (d *ESX5Driver) CreateDisk(diskPathLocal string, size string, adapter_type string, typeId string) error { - diskPath := d.datastorePath(diskPathLocal) - diskPath = strings.Replace(diskPath, " ", `\ `, -1) + diskPath := fmt.Sprintf("'%s'", d.datastorePath(diskPathLocal)) return d.sh("vmkfstools", "-c", size, "-d", typeId, "-a", adapter_type, diskPath) } From 8cba32d5265d973a4c0c210c68be9671940de435 Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Thu, 11 Oct 2018 16:28:04 -0700 Subject: [PATCH 2/7] escape all the d.sh calls that contain paths --- builder/vmware/iso/driver_esx5.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/builder/vmware/iso/driver_esx5.go b/builder/vmware/iso/driver_esx5.go index 63b29a021..c9be08edd 100644 --- a/builder/vmware/iso/driver_esx5.go +++ b/builder/vmware/iso/driver_esx5.go @@ -47,11 +47,11 @@ func (d *ESX5Driver) Clone(dst, src string, linked bool) error { func (d *ESX5Driver) CompactDisk(diskPathLocal string) error { diskPath := d.datastorePath(diskPathLocal) - return d.sh("vmkfstools", "--punchzero", diskPath) + return d.sh("vmkfstools", "--punchzero", fmt.Sprintf("\"%s\"", diskPath)) } func (d *ESX5Driver) CreateDisk(diskPathLocal string, size string, adapter_type string, typeId string) error { - diskPath := fmt.Sprintf("'%s'", d.datastorePath(diskPathLocal)) + diskPath := fmt.Sprintf("\"%s\"", d.datastorePath(diskPathLocal)) return d.sh("vmkfstools", "-c", size, "-d", typeId, "-a", adapter_type, diskPath) } @@ -113,7 +113,7 @@ func (d *ESX5Driver) Destroy() error { } func (d *ESX5Driver) IsDestroyed() (bool, error) { - err := d.sh("test", "!", "-e", d.outputDir) + err := d.sh("test", "!", "-e", fmt.Sprintf("\"%s\"", d.outputDir)) if err != nil { return false, err } @@ -142,7 +142,7 @@ func (d *ESX5Driver) UploadISO(localPath string, checksum string, checksumType s func (d *ESX5Driver) RemoveCache(localPath string) error { finalPath := d.cachePath(localPath) log.Printf("Removing remote cache path %s (local %s)", finalPath, localPath) - return d.sh("rm", "-f", finalPath) + return d.sh("rm", "-f", fmt.Sprintf("\"%s\"", finalPath)) } func (d *ESX5Driver) ToolsIsoPath(string) string { @@ -450,7 +450,7 @@ func (d *ESX5Driver) CommHost(state multistep.StateBag) (string, error) { //------------------------------------------------------------------- func (d *ESX5Driver) DirExists() (bool, error) { - err := d.sh("test", "-e", d.outputDir) + err := d.sh("test", "-e", fmt.Sprintf("\"%s\"", d.outputDir)) return err == nil, nil } @@ -482,11 +482,11 @@ func (d *ESX5Driver) MkdirAll() error { } func (d *ESX5Driver) Remove(path string) error { - return d.sh("rm", path) + return d.sh("rm", fmt.Sprintf("\"%s\"", path)) } func (d *ESX5Driver) RemoveAll() error { - return d.sh("rm", "-rf", d.outputDir) + return d.sh("rm", "-rf", fmt.Sprintf("\"%s\"", d.outputDir)) } func (d *ESX5Driver) SetOutputDir(path string) { @@ -579,7 +579,7 @@ func (d *ESX5Driver) checkGuestIPHackEnabled() error { } func (d *ESX5Driver) mkdir(path string) error { - return d.sh("mkdir", "-p", path) + return d.sh("mkdir", "-p", fmt.Sprintf("\"%s\"", path)) } func (d *ESX5Driver) upload(dst, src string) error { @@ -593,7 +593,7 @@ func (d *ESX5Driver) upload(dst, src string) error { func (d *ESX5Driver) verifyChecksum(ctype string, hash string, file string) bool { if ctype == "none" { - if err := d.sh("stat", file); err != nil { + if err := d.sh("stat", fmt.Sprintf("\"%s\"", file)); err != nil { return false } } else { From 3f591d78f39d13eece14cdb1f0de9a996add7055 Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Fri, 12 Oct 2018 09:58:24 -0700 Subject: [PATCH 3/7] quote vmx path in register function --- builder/vmware/iso/driver_esx5.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builder/vmware/iso/driver_esx5.go b/builder/vmware/iso/driver_esx5.go index c9be08edd..6a98d3399 100644 --- a/builder/vmware/iso/driver_esx5.go +++ b/builder/vmware/iso/driver_esx5.go @@ -92,7 +92,7 @@ func (d *ESX5Driver) Register(vmxPathLocal string) error { if err := d.upload(vmxPath, vmxPathLocal); err != nil { return err } - r, err := d.run(nil, "vim-cmd", "solo/registervm", vmxPath) + r, err := d.run(nil, "vim-cmd", "solo/registervm", fmt.Sprintf("\"%s\"", vmxPath)) if err != nil { return err } From 1e4133cbf92299c867c7e211cb4b285590070e4a Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Fri, 12 Oct 2018 13:33:42 -0700 Subject: [PATCH 4/7] quote upload path --- builder/vmware/iso/driver_esx5.go | 6 ++++++ communicator/ssh/communicator.go | 2 ++ 2 files changed, 8 insertions(+) diff --git a/builder/vmware/iso/driver_esx5.go b/builder/vmware/iso/driver_esx5.go index 6a98d3399..803d797b4 100644 --- a/builder/vmware/iso/driver_esx5.go +++ b/builder/vmware/iso/driver_esx5.go @@ -89,13 +89,18 @@ func (d *ESX5Driver) Stop(vmxPathLocal string) error { func (d *ESX5Driver) Register(vmxPathLocal string) error { vmxPath := filepath.ToSlash(filepath.Join(d.outputDir, filepath.Base(vmxPathLocal))) + log.Printf("DEBUGGING 6794 (1): upload path is: %s", vmxPath) if err := d.upload(vmxPath, vmxPathLocal); err != nil { + log.Printf("DEBUGGING 6794 (2): upload errored: %s", err.Error()) return err } + log.Printf("DEBUGGING 6794 (3): Upload succeeded") r, err := d.run(nil, "vim-cmd", "solo/registervm", fmt.Sprintf("\"%s\"", vmxPath)) if err != nil { + log.Printf("DEBUGGING 6794 (4): VM registration errorred: %s", err.Error()) return err } + log.Printf("DEBUGGING 6794 (5): Registration succeeded") d.vmId = strings.TrimRight(r, "\n") return nil } @@ -585,6 +590,7 @@ func (d *ESX5Driver) mkdir(path string) error { func (d *ESX5Driver) upload(dst, src string) error { f, err := os.Open(src) if err != nil { + log.Printf("DEBUGGING 6794 (6): unable to open src file for scp upload") return err } defer f.Close() diff --git a/communicator/ssh/communicator.go b/communicator/ssh/communicator.go index 8fbddc968..ebeacfeab 100644 --- a/communicator/ssh/communicator.go +++ b/communicator/ssh/communicator.go @@ -563,6 +563,8 @@ func (c *comm) scpUploadSession(path string, input io.Reader, fi *os.FileInfo) e // The target directory and file for talking the SCP protocol target_dir := filepath.Dir(path) target_file := filepath.Base(path) + log.Printf("DEBUGGING 6794 (7): target dir is %s", target_dir) + log.Printf("DEBUGGING 6794 (8): target file is %s", target_file) // On windows, filepath.Dir uses backslash separators (ie. "\tmp"). // This does not work when the target host is unix. Switch to forward slash From 18c5e8deb824fd8d6e35c59d14616205e0e57ddf Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Fri, 19 Oct 2018 13:46:55 -0700 Subject: [PATCH 5/7] fix --- builder/vmware/iso/driver_esx5.go | 6 ------ communicator/ssh/communicator.go | 4 ++-- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/builder/vmware/iso/driver_esx5.go b/builder/vmware/iso/driver_esx5.go index 803d797b4..6a98d3399 100644 --- a/builder/vmware/iso/driver_esx5.go +++ b/builder/vmware/iso/driver_esx5.go @@ -89,18 +89,13 @@ func (d *ESX5Driver) Stop(vmxPathLocal string) error { func (d *ESX5Driver) Register(vmxPathLocal string) error { vmxPath := filepath.ToSlash(filepath.Join(d.outputDir, filepath.Base(vmxPathLocal))) - log.Printf("DEBUGGING 6794 (1): upload path is: %s", vmxPath) if err := d.upload(vmxPath, vmxPathLocal); err != nil { - log.Printf("DEBUGGING 6794 (2): upload errored: %s", err.Error()) return err } - log.Printf("DEBUGGING 6794 (3): Upload succeeded") r, err := d.run(nil, "vim-cmd", "solo/registervm", fmt.Sprintf("\"%s\"", vmxPath)) if err != nil { - log.Printf("DEBUGGING 6794 (4): VM registration errorred: %s", err.Error()) return err } - log.Printf("DEBUGGING 6794 (5): Registration succeeded") d.vmId = strings.TrimRight(r, "\n") return nil } @@ -590,7 +585,6 @@ func (d *ESX5Driver) mkdir(path string) error { func (d *ESX5Driver) upload(dst, src string) error { f, err := os.Open(src) if err != nil { - log.Printf("DEBUGGING 6794 (6): unable to open src file for scp upload") return err } defer f.Close() diff --git a/communicator/ssh/communicator.go b/communicator/ssh/communicator.go index ebeacfeab..3c2fd0490 100644 --- a/communicator/ssh/communicator.go +++ b/communicator/ssh/communicator.go @@ -563,8 +563,8 @@ func (c *comm) scpUploadSession(path string, input io.Reader, fi *os.FileInfo) e // The target directory and file for talking the SCP protocol target_dir := filepath.Dir(path) target_file := filepath.Base(path) - log.Printf("DEBUGGING 6794 (7): target dir is %s", target_dir) - log.Printf("DEBUGGING 6794 (8): target file is %s", target_file) + // Escape spaces in remote directory + target_dir = strings.Replace(target_dir, " ", "\\ ", -1) // On windows, filepath.Dir uses backslash separators (ie. "\tmp"). // This does not work when the target host is unix. Switch to forward slash From 7d40aeaa33d075d947619aae6428c08188695b80 Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Fri, 19 Oct 2018 14:24:56 -0700 Subject: [PATCH 6/7] this needs to be _below_ the call to ToPath --- communicator/ssh/communicator.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/communicator/ssh/communicator.go b/communicator/ssh/communicator.go index 3c2fd0490..a6ebeefa2 100644 --- a/communicator/ssh/communicator.go +++ b/communicator/ssh/communicator.go @@ -563,14 +563,15 @@ func (c *comm) scpUploadSession(path string, input io.Reader, fi *os.FileInfo) e // The target directory and file for talking the SCP protocol target_dir := filepath.Dir(path) target_file := filepath.Base(path) - // Escape spaces in remote directory - target_dir = strings.Replace(target_dir, " ", "\\ ", -1) // On windows, filepath.Dir uses backslash separators (ie. "\tmp"). // This does not work when the target host is unix. Switch to forward slash // which works for unix and windows target_dir = filepath.ToSlash(target_dir) + // Escape spaces in remote directory + target_dir = strings.Replace(target_dir, " ", "\\ ", -1) + scpFunc := func(w io.Writer, stdoutR *bufio.Reader) error { return scpUploadFile(target_file, input, w, stdoutR, fi) } From fd8a85042d7d891585c7a53e3666302ae8e70eda Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Mon, 22 Oct 2018 10:45:54 -0700 Subject: [PATCH 7/7] use strconv.Quote instead of fmt.Sprint --- builder/vmware/iso/driver_esx5.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/builder/vmware/iso/driver_esx5.go b/builder/vmware/iso/driver_esx5.go index 6a98d3399..2f37f60b9 100644 --- a/builder/vmware/iso/driver_esx5.go +++ b/builder/vmware/iso/driver_esx5.go @@ -11,6 +11,7 @@ import ( "net" "os" "path/filepath" + "strconv" "strings" "time" @@ -47,11 +48,11 @@ func (d *ESX5Driver) Clone(dst, src string, linked bool) error { func (d *ESX5Driver) CompactDisk(diskPathLocal string) error { diskPath := d.datastorePath(diskPathLocal) - return d.sh("vmkfstools", "--punchzero", fmt.Sprintf("\"%s\"", diskPath)) + return d.sh("vmkfstools", "--punchzero", strconv.Quote(diskPath)) } func (d *ESX5Driver) CreateDisk(diskPathLocal string, size string, adapter_type string, typeId string) error { - diskPath := fmt.Sprintf("\"%s\"", d.datastorePath(diskPathLocal)) + diskPath := strconv.Quote(d.datastorePath(diskPathLocal)) return d.sh("vmkfstools", "-c", size, "-d", typeId, "-a", adapter_type, diskPath) } @@ -92,7 +93,7 @@ func (d *ESX5Driver) Register(vmxPathLocal string) error { if err := d.upload(vmxPath, vmxPathLocal); err != nil { return err } - r, err := d.run(nil, "vim-cmd", "solo/registervm", fmt.Sprintf("\"%s\"", vmxPath)) + r, err := d.run(nil, "vim-cmd", "solo/registervm", strconv.Quote(vmxPath)) if err != nil { return err } @@ -113,7 +114,7 @@ func (d *ESX5Driver) Destroy() error { } func (d *ESX5Driver) IsDestroyed() (bool, error) { - err := d.sh("test", "!", "-e", fmt.Sprintf("\"%s\"", d.outputDir)) + err := d.sh("test", "!", "-e", strconv.Quote(d.outputDir)) if err != nil { return false, err } @@ -142,7 +143,7 @@ func (d *ESX5Driver) UploadISO(localPath string, checksum string, checksumType s func (d *ESX5Driver) RemoveCache(localPath string) error { finalPath := d.cachePath(localPath) log.Printf("Removing remote cache path %s (local %s)", finalPath, localPath) - return d.sh("rm", "-f", fmt.Sprintf("\"%s\"", finalPath)) + return d.sh("rm", "-f", strconv.Quote(finalPath)) } func (d *ESX5Driver) ToolsIsoPath(string) string { @@ -450,7 +451,7 @@ func (d *ESX5Driver) CommHost(state multistep.StateBag) (string, error) { //------------------------------------------------------------------- func (d *ESX5Driver) DirExists() (bool, error) { - err := d.sh("test", "-e", fmt.Sprintf("\"%s\"", d.outputDir)) + err := d.sh("test", "-e", strconv.Quote(d.outputDir)) return err == nil, nil } @@ -482,11 +483,11 @@ func (d *ESX5Driver) MkdirAll() error { } func (d *ESX5Driver) Remove(path string) error { - return d.sh("rm", fmt.Sprintf("\"%s\"", path)) + return d.sh("rm", strconv.Quote(path)) } func (d *ESX5Driver) RemoveAll() error { - return d.sh("rm", "-rf", fmt.Sprintf("\"%s\"", d.outputDir)) + return d.sh("rm", "-rf", strconv.Quote(d.outputDir)) } func (d *ESX5Driver) SetOutputDir(path string) { @@ -579,7 +580,7 @@ func (d *ESX5Driver) checkGuestIPHackEnabled() error { } func (d *ESX5Driver) mkdir(path string) error { - return d.sh("mkdir", "-p", fmt.Sprintf("\"%s\"", path)) + return d.sh("mkdir", "-p", strconv.Quote(path)) } func (d *ESX5Driver) upload(dst, src string) error { @@ -593,7 +594,7 @@ func (d *ESX5Driver) upload(dst, src string) error { func (d *ESX5Driver) verifyChecksum(ctype string, hash string, file string) bool { if ctype == "none" { - if err := d.sh("stat", fmt.Sprintf("\"%s\"", file)); err != nil { + if err := d.sh("stat", strconv.Quote(file)); err != nil { return false } } else {