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
This commit is contained in:
Marcus Efraimsson 2021-11-09 11:18:21 +01:00 committed by GitHub
parent 78e9fe520b
commit 36cea0b48e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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