From 36cea0b48e87f2dfe8ae5a447bce88f9407e7caa Mon Sep 17 00:00:00 2001 From: Marcus Efraimsson Date: Tue, 9 Nov 2021 11:18:21 +0100 Subject: [PATCH] Cli: Improve error handling for installing plugins (#41257) Improves error handling when installing plugins by checking for error before adding a defer of closing of the zip reader to not create a panic when there's an invalid zip file. Fixes #41029 --- pkg/plugins/manager/installer/installer.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pkg/plugins/manager/installer/installer.go b/pkg/plugins/manager/installer/installer.go index dac982a2f8e..3d21246e008 100644 --- a/pkg/plugins/manager/installer/installer.go +++ b/pkg/plugins/manager/installer/installer.go @@ -527,14 +527,16 @@ func (i *Installer) extractFiles(archiveFile string, pluginID string, dest strin } r, err := zip.OpenReader(archiveFile) + if err != nil { + return err + } + defer func() { if err := r.Close(); err != nil { i.log.Warn("failed to close zip file", "err", err) } }() - if err != nil { - return err - } + for _, zf := range r.File { // We can ignore gosec G305 here since we check for the ZipSlip vulnerability below // nolint:gosec