Skip to content

Commit fa40153

Browse files
authored
Merge pull request lxc#2172 from stgraber/main
incusd/instance/lxc: Tweak OCI entrypoint escaping
2 parents 07452f7 + a3eb0d0 commit fa40153

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

internal/server/instance/drivers/driver_lxc.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2367,15 +2367,22 @@ func (d *lxc) startCommon() (string, []func() error, error) {
23672367
}
23682368
}
23692369

2370+
// Compute the entrypoint string.
2371+
initCmd := shellquote.Join(entrypoint...)
2372+
2373+
// As we feed this to execve and not to a real shell, un-escape some sequences.
2374+
initCmd = strings.ReplaceAll(initCmd, "\\(", "(")
2375+
initCmd = strings.ReplaceAll(initCmd, "\\)", ")")
2376+
23702377
if len(entrypoint) > 0 && slices.Contains([]string{"/init", "/sbin/init", "/s6-init"}, entrypoint[0]) {
23712378
// For regular init systems, call them directly as PID1.
2372-
err = lxcSetConfigItem(cc, "lxc.init.cmd", shellquote.Join(entrypoint...))
2379+
err = lxcSetConfigItem(cc, "lxc.init.cmd", initCmd)
23732380
if err != nil {
23742381
return "", nil, err
23752382
}
23762383
} else {
23772384
// For anything else, run them under our own PID1.
2378-
err = lxcSetConfigItem(cc, "lxc.execute.cmd", shellquote.Join(entrypoint...))
2385+
err = lxcSetConfigItem(cc, "lxc.execute.cmd", initCmd)
23792386
if err != nil {
23802387
return "", nil, err
23812388
}

0 commit comments

Comments
 (0)