summaryrefslogtreecommitdiff
path: root/cmd/podman/runlabel.go
diff options
context:
space:
mode:
authorValentin Rothberg <vrothberg@suse.com>2018-10-05 14:36:27 +0200
committerValentin Rothberg <vrothberg@suse.com>2018-10-05 17:28:18 +0200
commitd4eca12cc12734f2b578e1b1967d69889c21c487 (patch)
tree872d4e8270a2778a4c995d30cd3011682b1ebfb2 /cmd/podman/runlabel.go
parent094b8b73505cb084d632ebb08e2a014e68f5e1b1 (diff)
downloadpodman-d4eca12cc12734f2b578e1b1967d69889c21c487.tar.gz
podman-d4eca12cc12734f2b578e1b1967d69889c21c487.tar.bz2
podman-d4eca12cc12734f2b578e1b1967d69889c21c487.zip
runlabel: execute /proc/self/exe and avoid recursion
Execute /proc/self/exe instead of podman. This makes the runlabel command more portable as it works for binaries outside the path as well as for local builds. Also, avoid redundantly executing the runlabel command by setting the PODMAN_RUNLABEL_NESTED environment variable to "1". Podman now checks for this variable before executing the runlabel command and will throw an error in case the variable is set. Signed-off-by: Valentin Rothberg <vrothberg@suse.com>
Diffstat (limited to 'cmd/podman/runlabel.go')
-rw-r--r--cmd/podman/runlabel.go9
1 files changed, 9 insertions, 0 deletions
diff --git a/cmd/podman/runlabel.go b/cmd/podman/runlabel.go
index c5dd98ee6..34e6b9093 100644
--- a/cmd/podman/runlabel.go
+++ b/cmd/podman/runlabel.go
@@ -94,6 +94,14 @@ func runlabelCmd(c *cli.Context) error {
newImage *image.Image
)
+ // Evil images could trick into recursively executing the runlabel
+ // command. Avoid this by setting the "PODMAN_RUNLABEL_NESTED" env
+ // variable when executing a label first.
+ nested := os.Getenv("PODMAN_RUNLABEL_NESTED")
+ if nested == "1" {
+ return fmt.Errorf("nested runlabel calls: runlabels cannot execute the runlabel command")
+ }
+
opts := make(map[string]string)
runtime, err := libpodruntime.GetRuntime(c)
if err != nil {
@@ -177,6 +185,7 @@ func runlabelCmd(c *cli.Context) error {
cmd := shared.GenerateCommand(runLabel, imageName, c.String("name"))
env := shared.GenerateRunEnvironment(c.String("name"), imageName, opts)
+ env = append(env, "PODMAN_RUNLABEL_NESTED=1")
if !c.Bool("quiet") {
fmt.Printf("Command: %s\n", strings.Join(cmd, " "))