Skip to content

Commit ad43df5

Browse files
Danial-Gharibvvoland
authored andcommitted
configfile: Initialize nil AuthConfigs
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 <danial.mail.gh@gmail.com> Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
1 parent 803d4a9 commit ad43df5

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

cli/config/configfile/file.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ func (configFile *ConfigFile) ContainsAuth() bool {
9494

9595
// GetAuthConfigs returns the mapping of repo to auth configuration
9696
func (configFile *ConfigFile) GetAuthConfigs() map[string]types.AuthConfig {
97+
if configFile.AuthConfigs == nil {
98+
configFile.AuthConfigs = make(map[string]types.AuthConfig)
99+
}
97100
return configFile.AuthConfigs
98101
}
99102

cli/config/credentials/file_store.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ func (c *fileStore) GetAll() (map[string]types.AuthConfig, error) {
5252

5353
// Store saves the given credentials in the file store.
5454
func (c *fileStore) Store(authConfig types.AuthConfig) error {
55-
c.file.GetAuthConfigs()[authConfig.ServerAddress] = authConfig
55+
authConfigs := c.file.GetAuthConfigs()
56+
authConfigs[authConfig.ServerAddress] = authConfig
5657
return c.file.Save()
5758
}
5859

0 commit comments

Comments
 (0)