Skip to content
This repository was archived by the owner on Oct 19, 2022. It is now read-only.

Commit acc3f89

Browse files
committed
Make sshfs shelling-out more robust
Signed-off-by: Tibor Vass <teabee89@gmail.com>
1 parent 776485c commit acc3f89

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

main.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"os/exec"
1111
"path/filepath"
1212
"strconv"
13+
"strings"
1314
"sync"
1415

1516
"github.com/Sirupsen/logrus"
@@ -231,15 +232,16 @@ func (d *sshfsDriver) Capabilities(r volume.Request) volume.Response {
231232
}
232233

233234
func (d *sshfsDriver) mountVolume(v *sshfsVolume) error {
234-
cmd := fmt.Sprintf("sshfs -oStrictHostKeyChecking=no %s %s", v.Sshcmd, v.Mountpoint)
235+
cmd := exec.Command("sshfs", "-oStrictHostKeyChecking=no", v.Sshcmd, v.Mountpoint)
235236
if v.Port != "" {
236-
cmd = fmt.Sprintf("%s -p %s", cmd, v.Port)
237+
cmd.Args = append(cmd.Args, "-p", v.Port)
237238
}
238239
if v.Password != "" {
239-
cmd = fmt.Sprintf("echo %s | %s -o workaround=rename -o password_stdin", v.Password, cmd)
240+
cmd.Args = append(cmd.Args, "-p", v.Port, "-o", "workaround=rename", "-o", "password_stdin")
241+
cmd.Stdin = strings.NewReader(v.Password)
240242
}
241-
logrus.Debug(cmd)
242-
return exec.Command("sh", "-c", cmd).Run()
243+
logrus.Debug(cmd.Args)
244+
return cmd.Run()
243245
}
244246

245247
func (d *sshfsDriver) unmountVolume(target string) error {

0 commit comments

Comments
 (0)