From b0dca399b1946778d641d35196300393e2adb15a Mon Sep 17 00:00:00 2001 From: Danial Date: Thu, 13 Jul 2023 02:27:39 +0330 Subject: [PATCH] configfile: Initialize nil AuthConfigs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Initialize AuthConfigs map if it's nil before returning it. This fixes fileStore.Store nil dereference panic when adding a new key to the map. Signed-off-by: Danial Gharib Signed-off-by: Paweł Gronowski (cherry picked from commit ad43df5e86f990a7e768087e546f1da75b887023) --- cli/config/configfile/file.go | 3 +++ cli/config/credentials/file_store.go | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/cli/config/configfile/file.go b/cli/config/configfile/file.go index 609a88c278..579154d77f 100644 --- a/cli/config/configfile/file.go +++ b/cli/config/configfile/file.go @@ -95,6 +95,9 @@ func (configFile *ConfigFile) ContainsAuth() bool { // GetAuthConfigs returns the mapping of repo to auth configuration func (configFile *ConfigFile) GetAuthConfigs() map[string]types.AuthConfig { + if configFile.AuthConfigs == nil { + configFile.AuthConfigs = make(map[string]types.AuthConfig) + } return configFile.AuthConfigs } diff --git a/cli/config/credentials/file_store.go b/cli/config/credentials/file_store.go index de1c676e50..ea30fc3006 100644 --- a/cli/config/credentials/file_store.go +++ b/cli/config/credentials/file_store.go @@ -52,7 +52,8 @@ func (c *fileStore) GetAll() (map[string]types.AuthConfig, error) { // Store saves the given credentials in the file store. func (c *fileStore) Store(authConfig types.AuthConfig) error { - c.file.GetAuthConfigs()[authConfig.ServerAddress] = authConfig + authConfigs := c.file.GetAuthConfigs() + authConfigs[authConfig.ServerAddress] = authConfig return c.file.Save() }