diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2021-02-01 12:45:11 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-01 12:45:11 -0500 |
commit | 182e8414d406d3058e985104af98f30a9e8f56fa (patch) | |
tree | 7ce06e9fab81e63476b43bcefa746520abdf7b91 /pkg/systemd/generate/common.go | |
parent | 20183349fd2c6a9a569c6c79234af48bb5d92ff7 (diff) | |
parent | 5352df226bc3f345836e78b73063de91d34b4e85 (diff) | |
download | podman-182e8414d406d3058e985104af98f30a9e8f56fa.tar.gz podman-182e8414d406d3058e985104af98f30a9e8f56fa.tar.bz2 podman-182e8414d406d3058e985104af98f30a9e8f56fa.zip |
Merge pull request #9178 from Luap99/fix-9176
Fix podman generate systemd --new special char handling
Diffstat (limited to 'pkg/systemd/generate/common.go')
-rw-r--r-- | pkg/systemd/generate/common.go | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/pkg/systemd/generate/common.go b/pkg/systemd/generate/common.go index de6751a17..e9902319c 100644 --- a/pkg/systemd/generate/common.go +++ b/pkg/systemd/generate/common.go @@ -60,13 +60,21 @@ func filterPodFlags(command []string) []string { return processed } -// quoteArguments makes sure that all arguments with at least one whitespace +// escapeSystemdArguments makes sure that all arguments with at least one whitespace // are quoted to make sure those are interpreted as one argument instead of -// multiple ones. -func quoteArguments(command []string) []string { +// multiple ones. Also make sure to escape all characters which have a special +// meaning to systemd -> $,% and \ +// see: https://www.freedesktop.org/software/systemd/man/systemd.service.html#Command%20lines +func escapeSystemdArguments(command []string) []string { for i := range command { + command[i] = strings.ReplaceAll(command[i], "$", "$$") + command[i] = strings.ReplaceAll(command[i], "%", "%%") if strings.ContainsAny(command[i], " \t") { command[i] = strconv.Quote(command[i]) + } else if strings.Contains(command[i], `\`) { + // strconv.Quote also escapes backslashes so + // we should replace only if strconv.Quote was not used + command[i] = strings.ReplaceAll(command[i], `\`, `\\`) } } return command |