Skip to content

Commit 714551f

Browse files
authored
Merge pull request #907 from rancher-sandbox/show-ssh
Protect quotes in show-ssh output
2 parents 18e98dc + a5c0fcd commit 714551f

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

cmd/limactl/show_ssh.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,21 +96,29 @@ func showSSHAction(cmd *cobra.Command, args []string) error {
9696
return formatSSH(w, instName, format, opts)
9797
}
9898

99+
func quoteOption(o string) string {
100+
// make sure the shell doesn't swallow quotes in option values
101+
if strings.ContainsRune(o, '"') {
102+
o = "'" + o + "'"
103+
}
104+
return o
105+
}
106+
99107
func formatSSH(w io.Writer, instName, format string, opts []string) error {
100108
fakeHostname := "lima-" + instName // corresponds to the default guest hostname
101109
switch format {
102110
case showSSHFormatCmd:
103111
args := []string{"ssh"}
104112
for _, o := range opts {
105-
args = append(args, "-o", o)
113+
args = append(args, "-o", quoteOption(o))
106114
}
107115
args = append(args, fakeHostname)
108116
// the args are similar to `limactl shell` but not exactly same. (e.g., lacks -t)
109117
fmt.Fprintln(w, strings.Join(args, " ")) // no need to use shellescape.QuoteCommand
110118
case showSSHFormatArgs:
111119
var args []string
112120
for _, o := range opts {
113-
args = append(args, "-o", o)
121+
args = append(args, "-o", quoteOption(o))
114122
}
115123
fmt.Fprintln(w, strings.Join(args, " ")) // no need to use shellescape.QuoteCommand
116124
case showSSHFormatOptions:

0 commit comments

Comments
 (0)