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 <m.dmitrichenko222@gmail.com>
This commit is contained in:
Mikhail Dmitrichenko
2025-11-20 17:22:08 +03:00
parent 6541fc4fb2
commit 8411881ab2

View File

@@ -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)
}