Skip to content

Commit f9867f3

Browse files
committed
Fix SSH command escaping (addresses #632)
Signed-off-by: Ryan Lester <[email protected]>
1 parent f24302b commit f9867f3

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

cmd/limactl/shell.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,10 @@ func shellAction(cmd *cobra.Command, args []string) error {
110110

111111
script := fmt.Sprintf("%s ; exec bash --login", changeDirCmd)
112112
if len(args) > 1 {
113-
script += fmt.Sprintf(" -c %q", shellescape.QuoteCommand(args[1:]))
113+
script += fmt.Sprintf(
114+
" -c %s",
115+
shellescape.Quote(shellescape.QuoteCommand(args[1:])),
116+
)
114117
}
115118

116119
arg0, err := exec.LookPath("ssh")

hack/test-example.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,12 @@ if [ "$got" != "$expected" ]; then
132132
exit 1
133133
fi
134134

135+
INFO "Testing limactl command with escaped characters"
136+
limactl shell "$NAME" bash -c "$(echo -e '\n\techo foo\n\techo bar')"
137+
138+
INFO "Testing limactl command with quotes"
139+
limactl shell "$NAME" bash -c "echo 'foo \"bar\"'"
140+
135141
if [[ -n ${CHECKS["systemd"]} ]]; then
136142
set -x
137143
if ! limactl shell "$NAME" systemctl is-system-running --wait; then

0 commit comments

Comments
 (0)