Prevent nil pointer deref in GetImage

Trying to print the image id on a failed inspect will result in a nil
pointer panic because the image will be nil.  Replace image.id with the
image name which is defined as a string without the use of inspect.

Fixes: bz#2131836

[NO NEW TESTS NEEDED]

Signed-off-by: Brent Baude <bbaude@redhat.com>
This commit is contained in:
Brent Baude 2022-10-04 15:12:27 -05:00 • committed by openshift-cherrypick-robot
parent 7154106256
commit 94d685c0d5

View file

@ -404,7 +404,7 @@ func GetImage(w http.ResponseWriter, r *http.Request) {
}
inspect, err := handlers.ImageDataToImageInspect(r.Context(), newImage)
if err != nil {
utils.Error(w, http.StatusInternalServerError, fmt.Errorf("failed to convert ImageData to ImageInspect '%s': %w", inspect.ID, err))
utils.Error(w, http.StatusInternalServerError, fmt.Errorf("failed to convert ImageData to ImageInspect '%s': %w", name, err))
return
}
utils.WriteResponse(w, http.StatusOK, inspect)