Skip to content

Commit

Permalink
Fix possible panic in libpod/image/prune.go
Browse files Browse the repository at this point in the history
podman image prune paniced locally for me. The error handling was not
done correctly and we could end up with a nil pointer dereference.

[NO TESTS NEEDED] I have no idea how I could force an error in img.Size().

Signed-off-by: Paul Holzinger <paul.holzinger@web.de>
  • Loading branch information
Paul Holzinger authored and jmguzik committed Apr 26, 2021
1 parent 6f73f38 commit 32e0957
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions libpod/image/prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,11 @@ func (ir *Runtime) PruneImages(ctx context.Context, all bool, filter []string) (
}
nameOrID := img.ID()
s, err := img.Size(ctx)
imgSize := *s
imgSize := uint64(0)
if err != nil {
logrus.Warnf("Failed to collect image size for: %s, %s", nameOrID, err)
imgSize = 0
} else {
imgSize = *s
}
if err := img.Remove(ctx, false); err != nil {
if errors.Cause(err) == storage.ErrImageUsedByContainer {
Expand Down

0 comments on commit 32e0957

Please sign in to comment.