From 42d7979d655a0aee7fd97d1c732a09b59933ea9e Mon Sep 17 00:00:00 2001 From: Achilleas Koutsou Date: Fri, 12 Nov 2021 11:31:53 +0100 Subject: [PATCH] api/v1: check for nil data before reading After parsing the osbuild output, immediately check if any data was set before dereferencing pointers. --- internal/cloudapi/v1/v1.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/internal/cloudapi/v1/v1.go b/internal/cloudapi/v1/v1.go index 4e04d6033..a0aacac78 100644 --- a/internal/cloudapi/v1/v1.go +++ b/internal/cloudapi/v1/v1.go @@ -522,6 +522,11 @@ func (h *apiHandlers) ComposeMetadata(ctx echo.Context, id string) error { return echo.NewHTTPError(http.StatusNotFound, "Job %s not found: %s", id, err) } + if result.OSBuildOutput == nil || result.OSBuildOutput.Stages == nil { + // no data to work with; parse error + return echo.NewHTTPError(http.StatusInternalServerError, "Failed to read metadata for job %s", id) + } + var job worker.OSBuildJob if _, _, _, err = h.server.workers.Job(jobId, &job); err != nil { return echo.NewHTTPError(http.StatusNotFound, "Job %s not found: %s", id, err)