Skip to content

Commit 23d5996

Browse files
committed
Escape password in cifs command line
1 parent 9092db7 commit 23d5996

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

netshare/drivers/cifs.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,10 @@ func (c CifsDriver) mountVolume(name, source, dest string, creds *CifsCreds) err
217217
}
218218

219219
if user != "" {
220-
opts.WriteString(fmt.Sprintf("username=%s,", user))
220+
// escape single quotes in password character as it will be quoted in command line
221+
opts.WriteString(fmt.Sprintf("username='%s',", strings.Replace(user, "'", "\\'", -1)))
221222
if pass != "" {
222-
opts.WriteString(fmt.Sprintf("password=%s,", pass))
223+
opts.WriteString(fmt.Sprintf("password='%s',", strings.Replace(pass, "'", "\\'", -1)))
223224
}
224225
} else {
225226
opts.WriteString("guest,")
@@ -245,7 +246,7 @@ func (c CifsDriver) mountVolume(name, source, dest string, creds *CifsCreds) err
245246

246247
opts.WriteString(fmt.Sprintf("%s %s", source, dest))
247248
cmd := fmt.Sprintf("mount -t cifs -o %s", opts.String())
248-
log.Debugf("Executing: %s\n", strings.Replace(cmd, "password="+pass, "password=****", 1))
249+
log.Debugf("Executing: %s\n", strings.Replace(cmd, "password='"+pass+"'", "password='****'", 1))
249250
return run(cmd)
250251
}
251252

0 commit comments

Comments
 (0)