From d1a45ce63a05709216e2ce4baad8b0170b1c41c7 Mon Sep 17 00:00:00 2001 From: Lucas Bajolet Date: Wed, 10 Apr 2024 17:27:20 -0400 Subject: [PATCH] packer: check if errs is nil before getting length When installing a remote plugin, and after we've either successfully installed a binary, or exhausted all the possible sources, we print a final error message if nothing was reported. However, given that errs is a pointer to a structure, and if no errors were produced, the the error list could be nil, leading to the call to `Len()' to crash Packer. This is exceedingly rare as in general the code attempts to read multiple sources from Github, and therefore we almost always get some error reported, but while changing the function's code, I managed to make it crash while removing/changing some error statements. Therefore to avoid future surprises, we first check that `errs' is not nil before invoking `Len()' on it, as no errors and no plugins installed mean that something went wrong all the same. --- packer/plugin-getter/plugins.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packer/plugin-getter/plugins.go b/packer/plugin-getter/plugins.go index b17f532a82c..73bbed12665 100644 --- a/packer/plugin-getter/plugins.go +++ b/packer/plugin-getter/plugins.go @@ -871,7 +871,7 @@ func (pr *Requirement) InstallLatest(opts InstallOptions) (*Installation, error) } } - if errs.Len() == 0 { + if errs == nil || errs.Len() == 0 { err := fmt.Errorf("could not find a local nor a remote checksum for plugin %q %q", pr.Identifier, pr.VersionConstraints) errs = multierror.Append(errs, err) }