From 62bb10bdf251762e3f0278d68f2f9da770a95775 Mon Sep 17 00:00:00 2001 From: Tigran Sogomonian Date: Tue, 15 Oct 2024 13:59:46 +0300 Subject: [PATCH 1/2] api: Remove double close in ImportImages tmpfile is closed using defer. Remove explicit closing. Found by Linux Verification Center (linuxtesting.org) with SVACE. Signed-off-by: Tigran Sogomonian --- pkg/api/handlers/libpod/images.go | 1 - 1 file changed, 1 deletion(-) diff --git a/pkg/api/handlers/libpod/images.go b/pkg/api/handlers/libpod/images.go index 26b899f002..c8ca847253 100644 --- a/pkg/api/handlers/libpod/images.go +++ b/pkg/api/handlers/libpod/images.go @@ -410,7 +410,6 @@ func ImagesImport(w http.ResponseWriter, r *http.Request) { return } - tmpfile.Close() source = tmpfile.Name() } From a2599f029aa8b57a2dee132e9fb4511cfa5183e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A2=D0=B8=D0=B3=D1=80=D0=B0=D0=BD=20=D0=A1=D0=BE=D0=B3?= =?UTF-8?q?=D0=BE=D0=BC=D0=BE=D0=BD=D1=8F=D0=BD?= Date: Tue, 15 Oct 2024 16:35:59 +0300 Subject: [PATCH 2/2] api: Replace close function in condition body MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit One close is returned to its place, the second one is replaced in the body of the error condition. Found by Linux Verification Center (linuxtesting.org) with SVACE. Signed-off-by: Тигран Согомонян --- pkg/api/handlers/libpod/images.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/pkg/api/handlers/libpod/images.go b/pkg/api/handlers/libpod/images.go index c8ca847253..9077de2231 100644 --- a/pkg/api/handlers/libpod/images.go +++ b/pkg/api/handlers/libpod/images.go @@ -118,9 +118,8 @@ func PruneImages(w http.ResponseWriter, r *http.Request) { runtime := r.Context().Value(api.RuntimeKey).(*libpod.Runtime) decoder := r.Context().Value(api.DecoderKey).(*schema.Decoder) query := struct { - All bool `schema:"all"` - External bool `schema:"external"` - BuildCache bool `schema:"buildcache"` + All bool `schema:"all"` + External bool `schema:"external"` }{ // override any golang type defaults } @@ -158,10 +157,9 @@ func PruneImages(w http.ResponseWriter, r *http.Request) { imageEngine := abi.ImageEngine{Libpod: runtime} pruneOptions := entities.ImagePruneOptions{ - All: query.All, - External: query.External, - Filter: libpodFilters, - BuildCache: query.BuildCache, + All: query.All, + External: query.External, + Filter: libpodFilters, } imagePruneReports, err := imageEngine.Prune(r.Context(), pruneOptions) if err != nil { @@ -403,13 +401,14 @@ func ImagesImport(w http.ResponseWriter, r *http.Request) { return } defer os.Remove(tmpfile.Name()) - defer tmpfile.Close() if _, err := io.Copy(tmpfile, r.Body); err != nil && err != io.EOF { utils.Error(w, http.StatusInternalServerError, fmt.Errorf("unable to write archive to temporary file: %w", err)) + tmpfile.Close() return } + tmpfile.Close() source = tmpfile.Name() }