From ad43df5e86f990a7e768087e546f1da75b887023 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 --- 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 5db7f8b827..442c31110b 100644 --- a/cli/config/configfile/file.go +++ b/cli/config/configfile/file.go @@ -94,6 +94,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() }