Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nil pointer dereference on loading the config file #4414

Closed
gabriellavengeo opened this issue Jul 11, 2023 · 3 comments · Fixed by #4418
Closed

Nil pointer dereference on loading the config file #4414

gabriellavengeo opened this issue Jul 11, 2023 · 3 comments · Fixed by #4418

Comments

@gabriellavengeo
Copy link
Contributor

Description

The following line causes a nil pointer dereference if auths is set to null in config.json:

c.file.GetAuthConfigs()[authConfig.ServerAddress] = authConfig

configfile.LoadFromReader() would override AuthConfigs and set it to nil even if it has been initialised to an empty map in New() prior to that:

AuthConfigs: make(map[string]types.AuthConfig),

err = configFile.LoadFromReader(file)

One doesn't need to manually edit the file for that to be the case as it can result from a failed login. The AuthConfigs field in the ConfigFile struct doesn't have an omitempty tag, therefore a null value is explicitly set in the marshalled JSON:

AuthConfigs map[string]types.AuthConfig `json:"auths"`

Therefore it is recommended to check explicitly if the output of c.file.GetAuthConfigs() is nil and/or return an empty map if the value is nil in:

return configFile.AuthConfigs

Additionally, adding an omitempty tag for the field may be advised, even though it must be noted that omitempty doesn't differentiate between an empty map and nil.

Reproduce

  1. Set "auths": null in ~/.docker/config.json
  2. Run docker login

Expected behavior

No response

docker version

Client:
 Cloud integration: v1.0.35
 Version:           24.0.2
 API version:       1.43
 Go version:        go1.20.4
 Git commit:        cb74dfc
 Built:             Thu May 25 21:53:15 2023
 OS/Arch:           windows/amd64
 Context:           default

Server: Docker Desktop 4.21.1 (114176)
 Engine:
  Version:          24.0.2
  API version:      1.43 (minimum version 1.24)
  Go version:       go1.20.4
  Git commit:       659604f9
  Built:            Thu May 25 21:52:13 2023
  OS/Arch:          windows/amd64
  Experimental:     false

docker info

Client:
 Version:    24.0.2
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.11.0
    Path:     C:\Program Files\Docker\cli-plugins\docker-buildx.exe
  compose: Docker Compose (Docker Inc.)
    Version:  v2.19.1
    Path:     C:\Program Files\Docker\cli-plugins\docker-compose.exe
  dev: Docker Dev Environments (Docker Inc.)
    Version:  v0.1.0
    Path:     C:\Program Files\Docker\cli-plugins\docker-dev.exe
  extension: Manages Docker extensions (Docker Inc.)
    Version:  v0.2.20
    Path:     C:\Program Files\Docker\cli-plugins\docker-extension.exe
  init: Creates Docker-related starter files for your project (Docker Inc.)
    Version:  v0.1.0-beta.6
    Path:     C:\Program Files\Docker\cli-plugins\docker-init.exe
  sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc.)
    Version:  0.6.0
    Path:     C:\Program Files\Docker\cli-plugins\docker-sbom.exe
  scan: Docker Scan (Docker Inc.)
    Version:  v0.26.0
    Path:     C:\Program Files\Docker\cli-plugins\docker-scan.exe
  scout: Command line tool for Docker Scout (Docker Inc.)
    Version:  0.16.1
    Path:     C:\Program Files\Docker\cli-plugins\docker-scout.exe

Server:
 Containers: 0
  Running: 0
  Paused: 0
  Stopped: 0
 Images: 1
 Server Version: 24.0.2
 Storage Driver: windowsfilter
  Windows:
 Logging Driver: json-file
 Plugins:
  Volume: local
  Network: ics internal l2bridge l2tunnel nat null overlay private transparent
  Log: awslogs etwlogs fluentd gcplogs gelf json-file local logentries splunk syslog
 Swarm: inactive
 Default Isolation: hyperv
 Kernel Version: 10.0 22621 (22621.1.amd64fre.ni_release.220506-1250)
 Operating System: Microsoft Windows Version 22H2 (OS Build 22621.1848)
 OSType: windows
 Architecture: x86_64
 CPUs: 16
 Total Memory: 15.73GiB
 Name: admin-pc
 ID: a70de266-b762-4a77-9fa4-65e7a75301c1
 Docker Root Dir: C:\ProgramData\Docker
 Debug Mode: false
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false
 Product License: Community Engine

Additional Info

docker login output and stack trace:

Authenticating with existing credentials...
panic: assignment to entry in nil map

goroutine 1 [running]:
github.com/docker/cli/cli/config/credentials.(*fileStore).Store(0xc000108ba0, {{0x0, 0x0}, {0x0, 0x0}, {0x0, 0x0}, {0x0, 0x0}, {0xe9b9b7, ...}, ...})
        /go/src/github.com/docker/cli/cli/config/credentials/file_store.go:55 +0x49
github.com/docker/cli/cli/config/credentials.(*nativeStore).Store(0xc000120060, {{0x0, 0x0}, {0x0, 0x0}, {0x0, 0x0}, {0x0, 0x0}, {0xe9b9b7, ...}, ...})
        /go/src/github.com/docker/cli/cli/config/credentials/native_store.go:95 +0xb5
github.com/docker/cli/cli/command/registry.runLogin({0x1065cd8, 0xc000710000}, {{0x0, 0x0}, {0x0, 0x0}, {0x0, 0x0}, 0x0})
        /go/src/github.com/docker/cli/cli/command/registry/login.go:156 +0x55d
github.com/docker/cli/cli/command/registry.NewLoginCommand.func1(0xc000005b00?, {0x1887368?, 0x0?, 0x0?})
        /go/src/github.com/docker/cli/cli/command/registry/login.go:46 +0x72
github.com/docker/cli/vendor/github.com/spf13/cobra.(*Command).execute(0xc000005b00, {0xc0004ae620, 0x0, 0x0})
        /go/src/github.com/docker/cli/vendor/github.com/spf13/cobra/command.go:940 +0x862
github.com/docker/cli/vendor/github.com/spf13/cobra.(*Command).ExecuteC(0xc000004300)
        /go/src/github.com/docker/cli/vendor/github.com/spf13/cobra/command.go:1068 +0x3bd
github.com/docker/cli/vendor/github.com/spf13/cobra.(*Command).Execute(...)
        /go/src/github.com/docker/cli/vendor/github.com/spf13/cobra/command.go:992
main.runDocker(0x0?)
        /go/src/github.com/docker/cli/cmd/docker/docker.go:263 +0x4b7
main.main()
        /go/src/github.com/docker/cli/cmd/docker/docker.go:274 +0x97

Debugger output:

(dlv) bt
0  0x00000000005500a6 in github.com/docker/cli/cli/config/configfile.(*ConfigFile).LoadFromReader
   at /go/src/github.com/docker/cli/cli/config/configfile/file.go:69
1  0x00000000005551dc in github.com/docker/cli/cli/config.load
   at /go/src/github.com/docker/cli/cli/config/config.go:113
2  0x000000000055530c in github.com/docker/cli/cli/config.LoadDefaultConfigFile
   at /go/src/github.com/docker/cli/cli/config/config.go:123
3  0x00000000009ea89c in github.com/docker/cli/cli/command.(*DockerCli).Initialize
   at /go/src/github.com/docker/cli/cli/command/cli.go:231
4  0x00000000009f541c in github.com/docker/cli/cli.(*TopLevelCommand).Initialize
   at /go/src/github.com/docker/cli/cli/cobra.go:181
5  0x0000000000e737dc in main.runDocker
   at ./docker.go:226
6  0x0000000000e73d37 in main.main
   at ./docker.go:273
7  0x000000000043a847 in runtime.main
   at /usr/local/go/src/runtime/proc.go:250
8  0x000000000046ba01 in runtime.goexit
   at /usr/local/go/src/runtime/asm_amd64.s:1598
@Edstub207
Copy link

@thaJeztah Where can we find this fix? We have a Windows 11 machine running Docker v4.21.1 which is hitting this issue.

For some reason our other machines on the same docker version haven't hit it, although, they are mostly Windows 10.

@vvoland
Copy link
Collaborator

vvoland commented Aug 4, 2023

The fix is a part of 24.0.5 CLI release which has been shipped with the latest Docker Desktop v4.22.

@PureKrome
Copy link

thanks heaps for the quick turn around on this 🐛 , awesome people!

Just did a fresh install of Win11 about 2 weeks ago. Have this bug. Just found this thread and noticed I'm on 4.21.1. Upgraded and we're all good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants