From c05987ddd3d0e92e7ca793b8fec6d6eb07fc0b80 Mon Sep 17 00:00:00 2001 From: Tigran Sogomonian Date: Tue, 15 Oct 2024 17:00:47 +0300 Subject: [PATCH 1/2] api: Replace close function in condition body The close is replaced in the body of the error condition. Found by Linux Verification Center (linuxtesting.org) with SVACE. Signed-off-by: Tigran Sogomonian --- pkg/api/handlers/libpod/images.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/api/handlers/libpod/images.go b/pkg/api/handlers/libpod/images.go index 26b899f002..6b5e5abb31 100644 --- a/pkg/api/handlers/libpod/images.go +++ b/pkg/api/handlers/libpod/images.go @@ -403,10 +403,10 @@ 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 } From 9f5bbecb9507690875694c646b2f0ea725c1e595 Mon Sep 17 00:00:00 2001 From: Tigran Sogomonian Date: Thu, 7 Nov 2024 14:53:15 +0300 Subject: [PATCH 2/2] api: Add error check Add error check during tmpfile close. Found by Linux Verification Center (linuxtesting.org) with SVACE. Signed-off-by: Tigran Sogomonian --- pkg/api/handlers/libpod/images.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/api/handlers/libpod/images.go b/pkg/api/handlers/libpod/images.go index 6b5e5abb31..3e35a0dbb4 100644 --- a/pkg/api/handlers/libpod/images.go +++ b/pkg/api/handlers/libpod/images.go @@ -410,7 +410,10 @@ func ImagesImport(w http.ResponseWriter, r *http.Request) { return } - tmpfile.Close() + if err := tmpfile.Close(); err != nil { + utils.Error(w, http.StatusInternalServerError, fmt.Errorf("unable to close tempfile: %w", err)) + return + } source = tmpfile.Name() }