summaryrefslogtreecommitdiff
path: root/libpod
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2021-12-01 18:19:11 +0100
committerGitHub <noreply@github.com>2021-12-01 18:19:11 +0100
commit078e633294b07027c9f531ac1e849bb5b3d779f8 (patch)
tree3a1f45529be2595e2de0894dea9509d1a561b8f0 /libpod
parent295a6f7dd086731448a1168a349f62d3035258ca (diff)
parente2b344728cb0869d14eb165496a5c436cd9fb650 (diff)
downloadpodman-078e633294b07027c9f531ac1e849bb5b3d779f8.tar.gz
podman-078e633294b07027c9f531ac1e849bb5b3d779f8.tar.bz2
podman-078e633294b07027c9f531ac1e849bb5b3d779f8.zip
Merge pull request #12462 from vrothberg/fix-12452
top: parse ps(1) args correctly
Diffstat (limited to 'libpod')
-rw-r--r--libpod/container_top_linux.go18
1 files changed, 17 insertions, 1 deletions
diff --git a/libpod/container_top_linux.go b/libpod/container_top_linux.go
index 0d4cba85e..d4f4ddfc1 100644
--- a/libpod/container_top_linux.go
+++ b/libpod/container_top_linux.go
@@ -4,6 +4,7 @@ package libpod
import (
"bufio"
+ "fmt"
"os"
"strconv"
"strings"
@@ -11,6 +12,7 @@ import (
"github.com/containers/podman/v3/libpod/define"
"github.com/containers/podman/v3/pkg/rootless"
"github.com/containers/psgo"
+ "github.com/google/shlex"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
@@ -51,7 +53,21 @@ func (c *Container) Top(descriptors []string) ([]string, error) {
return nil, psgoErr
}
- output, err = c.execPS(descriptors)
+ // Note that the descriptors to ps(1) must be shlexed (see #12452).
+ psDescriptors := []string{}
+ for _, d := range descriptors {
+ shSplit, err := shlex.Split(d)
+ if err != nil {
+ return nil, fmt.Errorf("parsing ps args: %v", err)
+ }
+ for _, s := range shSplit {
+ if s != "" {
+ psDescriptors = append(psDescriptors, s)
+ }
+ }
+ }
+
+ output, err = c.execPS(psDescriptors)
if err != nil {
return nil, errors.Wrapf(err, "error executing ps(1) in the container")
}