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:
@@ -527,14 +527,16 @@ func (i *Installer) extractFiles(archiveFile string, pluginID string, dest strin
|
|||||||
}
|
}
|
||||||
|
|
||||||
r, err := zip.OpenReader(archiveFile)
|
r, err := zip.OpenReader(archiveFile)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
if err := r.Close(); err != nil {
|
if err := r.Close(); err != nil {
|
||||||
i.log.Warn("failed to close zip file", "err", err)
|
i.log.Warn("failed to close zip file", "err", err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
for _, zf := range r.File {
|
for _, zf := range r.File {
|
||||||
// We can ignore gosec G305 here since we check for the ZipSlip vulnerability below
|
// We can ignore gosec G305 here since we check for the ZipSlip vulnerability below
|
||||||
// nolint:gosec
|
// nolint:gosec
|
||||||
|
|||||||
Reference in New Issue
Block a user