From acc3f8958b6eb1e6ef7e3ecf829591d41f32f5a5 Mon Sep 17 00:00:00 2001 From: Tibor Vass Date: Thu, 30 Mar 2017 13:29:17 -0700 Subject: [PATCH] Make sshfs shelling-out more robust Signed-off-by: Tibor Vass --- main.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index a368314..f60e054 100644 --- a/main.go +++ b/main.go @@ -10,6 +10,7 @@ import ( "os/exec" "path/filepath" "strconv" + "strings" "sync" "github.com/Sirupsen/logrus" @@ -231,15 +232,16 @@ func (d *sshfsDriver) Capabilities(r volume.Request) volume.Response { } func (d *sshfsDriver) mountVolume(v *sshfsVolume) error { - cmd := fmt.Sprintf("sshfs -oStrictHostKeyChecking=no %s %s", v.Sshcmd, v.Mountpoint) + cmd := exec.Command("sshfs", "-oStrictHostKeyChecking=no", v.Sshcmd, v.Mountpoint) if v.Port != "" { - cmd = fmt.Sprintf("%s -p %s", cmd, v.Port) + cmd.Args = append(cmd.Args, "-p", v.Port) } if v.Password != "" { - cmd = fmt.Sprintf("echo %s | %s -o workaround=rename -o password_stdin", v.Password, cmd) + cmd.Args = append(cmd.Args, "-p", v.Port, "-o", "workaround=rename", "-o", "password_stdin") + cmd.Stdin = strings.NewReader(v.Password) } - logrus.Debug(cmd) - return exec.Command("sh", "-c", cmd).Run() + logrus.Debug(cmd.Args) + return cmd.Run() } func (d *sshfsDriver) unmountVolume(target string) error {