← Back to Pull requests

filters: do not index an empty container command #29820

Open
nishantbkl3345-ship-it opened this pull request with 39 lines diff across 2 files
View on GitHub
nishantbkl3345-ship-it nishantbkl3345-ship-it commented on Sep 22, 2026 19:18 UTC
Author

podman ps --filter command=<value> panics with "index out of range [0] with length 0" when any container in the store has no command recorded. GenerateContainerFilterFuncs indexes Container.Command()[0] without first checking the length.

A container has no command whenever it was created without an explicit command and the image contributed no CMD. Passing --entrypoint on its own is the shortest way to get there:

podman create --name t --entrypoint /bin/true alpine
podman ps -a --filter command=true

specgenutil.FillOutSpecGen only sets SpecGenerator.Command when a command was given on the command line, CreateContainer only calls WithCommand when that field is non-nil, and the image CMD fallback in container_internal.go is skipped once an entrypoint is set, so config.Command stays empty. An image that declares an ENTRYPOINT and no CMD reaches the same state without passing any flag, and nothing rejects such a container at creation time.

The filter is used by podman ps, by the libpod and Docker-compat /containers/json endpoints and by podman auto-update --filter, so one container of this shape breaks container listing for the whole store. On the CLI the command aborts with a stack trace; over the API the panic handler turns it into a 500.

Skip containers that have no command, which is what the other readers of this field already do in completion.go, container_inspect.go and container_exec.go. The external container variant of the filter indexes the same way. It cannot be reached today because ListStorageContainer always fills a command in, but guard it identically so the crash cannot reappear if that ever changes.

<!-- Thanks for sending a pull request! -->

Checklist

Ensure you have completed the following checklist for your pull request to be reviewed:
<!-- Use [x] to mark as done, or click the checkbox after opening PR -->

  • I have read and understood our contributing guidelines and will not have more than two open PRs as a new contributor.

  • PR description, commit message, and GitHub comments are human-written, per LLM Policy

  • Certify you wrote the patch or otherwise have the right to pass it on as an open-source patch by signing all

  • commits. (git commit -s). (If needed, use git commit -s --amend). The author email must match
    the sign-off email address. See CONTRIBUTING.md
    for more information.
  • Referenced issues using Fixes: #00000 in commit message (if applicable)

  • Tests have been added/updated (or no tests are needed)

  • Documentation has been updated (or no documentation changes are needed)

  • All commits pass make validatepr (format/lint checks)

  • Release note entered in the section below (or None if no user-facing changes)
  • Does this PR introduce a user-facing change?

    <!--
    Write None if there are no user-facing changes, otherwise enter your release note below.
    Include "action required" if users need to take action when upgrading.
    -->

    ``release-note

    ``

    Diff: 39 lines (+38 / -1) across 2 files Reviewer: Honny1 Review duration: 19237m
    All Vouch review confidence checks passed
    Residual risk 0.03 = Change Risk (0.27) × (1 − Review Confidence (0.89)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.27 · 39 lines diff across 2 files
    0.27
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.89 · 2 substantive comment(s)
    0.89
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    89%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.221
    Real PR Conversation Timeline
    4 items
    packit-as-a-service[bot] packit-as-a-service[bot] commented on Sep 22, 2026 22:34 UTC
    Bot

    [NON-BLOCKING] Packit jobs failed. @podman-container-tools/packit-jobs please check. Everyone else, feel free to ignore.

    Honny1 Honny1 commented on code on Sep 23, 2026 08:55 UTC
    Code Review
    test/e2e/ps_test.go:1
    @@ -462,6 +462,32 @@ var _ = Describe("Podman ps", func() {
     		Expect(output).To(BeEmpty())
     	})
     
    +	// A container created with --entrypoint and no command of its own stores an
    +	// empty command, because the image CMD is not inherited once an entrypoint
    +	// is set. Filtering by command must skip such a container instead of
    +	// indexing into the empty command slice.
    +	It("podman ps filter by container command with a container that has no command", func() {
    +		noCommand := podmanTest.Podman([]string{"create", "--name", "nocommand", "--entrypoint", "/bin/true", ALPINE})

    Please use PodmanExitCleanly()

    Honny1 Honny1 requested changes on Sep 23, 2026 08:57 UTC
    Changes Requested Reviewer

    Just testing nit.

    Reviewers
    Assignees
    nishantbkl3345-ship-it nishantbkl3345-ship-it
    Labels
    risk: low confidence: 89.1% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 26.5% (LOW) · Higher = larger blast radius
    26.5%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 89.1% · Lower = rushed or shallow review
    89.1%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 2.9% · Safe to merge
    2.9%