Fixes: #21202
We add valid check about filters like network, images,
volumes did.
Signed-off-by: Kai Qiang Wu(Kennan) <wkqwu@cn.ibm.com>
| ... | ... |
@@ -20,6 +20,19 @@ var acceptedVolumeFilterTags = map[string]bool{
|
| 20 | 20 |
"dangling": true, |
| 21 | 21 |
} |
| 22 | 22 |
|
| 23 |
+var acceptedPsFilterTags = map[string]bool{
|
|
| 24 |
+ "ancestor": true, |
|
| 25 |
+ "before": true, |
|
| 26 |
+ "exited": true, |
|
| 27 |
+ "id": true, |
|
| 28 |
+ "isolation": true, |
|
| 29 |
+ "label": true, |
|
| 30 |
+ "name": true, |
|
| 31 |
+ "status": true, |
|
| 32 |
+ "since": true, |
|
| 33 |
+ "volume": true, |
|
| 34 |
+} |
|
| 35 |
+ |
|
| 23 | 36 |
// iterationAction represents possible outcomes happening during the container iteration. |
| 24 | 37 |
type iterationAction int |
| 25 | 38 |
|
| ... | ... |
@@ -128,7 +141,12 @@ func (daemon *Daemon) reducePsContainer(container *container.Container, ctx *lis |
| 128 | 128 |
func (daemon *Daemon) foldFilter(config *types.ContainerListOptions) (*listContext, error) {
|
| 129 | 129 |
psFilters := config.Filter |
| 130 | 130 |
|
| 131 |
+ if err := psFilters.Validate(acceptedPsFilterTags); err != nil {
|
|
| 132 |
+ return nil, err |
|
| 133 |
+ } |
|
| 134 |
+ |
|
| 131 | 135 |
var filtExited []int |
| 136 |
+ |
|
| 132 | 137 |
err := psFilters.WalkValues("exited", func(value string) error {
|
| 133 | 138 |
code, err := strconv.Atoi(value) |
| 134 | 139 |
if err != nil {
|
| ... | ... |
@@ -213,6 +213,12 @@ func assertContainerList(out string, expected []string) bool {
|
| 213 | 213 |
return true |
| 214 | 214 |
} |
| 215 | 215 |
|
| 216 |
+func (s *DockerSuite) TestPsListContainersInvalidFilterName(c *check.C) {
|
|
| 217 |
+ out, _, err := dockerCmdWithError("ps", "-f", "invalidFilter=test")
|
|
| 218 |
+ c.Assert(err, checker.NotNil) |
|
| 219 |
+ c.Assert(out, checker.Contains, "Invalid filter") |
|
| 220 |
+} |
|
| 221 |
+ |
|
| 216 | 222 |
func (s *DockerSuite) TestPsListContainersSize(c *check.C) {
|
| 217 | 223 |
// Problematic on Windows as it doesn't report the size correctly @swernli |
| 218 | 224 |
testRequires(c, DaemonIsLinux) |