From 8411881ab2dfbad5b6ec432130f8e7ecaa9de4c1 Mon Sep 17 00:00:00 2001 From: Mikhail Dmitrichenko Date: Thu, 20 Nov 2025 17:22:08 +0300 Subject: [PATCH] avoid potential nil ptr deref in image rm In function rm variable `report` might be initialized as nil as a result of call `registry.ImageEngine().Remove(registry.Context(), args, imageOpts)`. Then, there is a call `registry.SetExitCode(report.ExitCode)` without explicit nil check before. Check `len(rmErrors) > 0` doesn't guarantee that report is a non-nil value. So such call may lead to nil deref. This commit adds check `report` for nil before its dereference. Found by Linux Verification Center (linuxtesting.org) with SVACE. Signed-off-by: Mikhail Dmitrichenko --- cmd/podman/images/rm.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/podman/images/rm.go b/cmd/podman/images/rm.go index 42ebd176798..c053b9dda07 100644 --- a/cmd/podman/images/rm.go +++ b/cmd/podman/images/rm.go @@ -87,7 +87,7 @@ func rm(_ *cobra.Command, args []string) error { } } } - if len(rmErrors) > 0 { + if len(rmErrors) > 0 && report != nil { registry.SetExitCode(report.ExitCode) }