Fix a segfault in podman inspect -l w/ no containers

We also need to rework container/image inspect to be separate,
but that can happen in another PR.

Fixes #6472

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
This commit is contained in:
Matthew Heon
2020-06-02 17:10:57 -04:00
parent c4ccd7cbc1
commit 4b37d4d5af
2 changed files with 12 additions and 2 deletions

View File

@ -44,8 +44,10 @@ func getContainersAndInputByContext(all, latest bool, names []string, runtime *l
ctrs, err = runtime.GetAllContainers()
case latest:
ctr, err = runtime.GetLatestContainer()
rawInput = append(rawInput, ctr.ID())
ctrs = append(ctrs, ctr)
if err == nil {
rawInput = append(rawInput, ctr.ID())
ctrs = append(ctrs, ctr)
}
default:
for _, n := range names {
ctr, e := runtime.LookupContainer(n)

View File

@ -171,4 +171,12 @@ var _ = Describe("Podman inspect", func() {
Expect(imageData[0].HealthCheck.Interval).To(BeNumerically("==", 60000000000))
Expect(imageData[0].HealthCheck.Test).To(Equal([]string{"CMD-SHELL", "curl -f http://localhost/ || exit 1"}))
})
It("podman inspect --latest with no container fails", func() {
SkipIfRemote()
session := podmanTest.Podman([]string{"inspect", "--latest"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Not(Equal(0)))
})
})