From dd0a37d48078c1ca1c542a59cc5312c60affe8e7 Mon Sep 17 00:00:00 2001 From: izeau Date: Wed, 16 Aug 2023 23:56:08 +0200 Subject: [PATCH] Fix nil pointer dereference in auth config --- builtin/docker/platform.go | 2 +- builtin/docker/pull/builder.go | 4 ++-- builtin/docker/registry_docker.go | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/builtin/docker/platform.go b/builtin/docker/platform.go index d166fd2a924..ecf869984bd 100644 --- a/builtin/docker/platform.go +++ b/builtin/docker/platform.go @@ -722,7 +722,7 @@ func (p *Platform) pullImage(cli *client.Client, log hclog.Logger, ui terminal.U var authBase64 = "" //Check if auth configuration is not null - if (*p.config.Auth != Auth{}) { + if p.config.Auth != nil && *p.config.Auth != (Auth{}) { auth := types.AuthConfig{ Username: authConfig.Username, Password: authConfig.Password, diff --git a/builtin/docker/pull/builder.go b/builtin/docker/pull/builder.go index a39b173dbb1..6364be5da87 100644 --- a/builtin/docker/pull/builder.go +++ b/builtin/docker/pull/builder.go @@ -329,7 +329,7 @@ func (b *Builder) buildWithDocker( return status.Errorf(codes.Internal, "unable to generate authentication info for registry: %s", err) } encodedAuth = base64.URLEncoding.EncodeToString(buf) - } else if *b.config.Auth != (docker.Auth{}) { + } else if b.config.Auth != nil && *b.config.Auth != (docker.Auth{}) { //If EncodedAuth is not set, and Auth is, use Auth authBytes, err := json.Marshal(types.AuthConfig{ Username: authConfig.Username, @@ -394,7 +394,7 @@ func (b *Builder) buildWithImg( env := os.Environ() //Check if auth configuration is not null - if (*b.config.Auth != docker.Auth{}) { + if b.config.Auth != nil && *b.config.Auth != (docker.Auth{}) { auth, err := json.Marshal(types.AuthConfig{ Username: authConfig.Username, Password: authConfig.Password, diff --git a/builtin/docker/registry_docker.go b/builtin/docker/registry_docker.go index 8a634abbdef..1e2de3060fd 100644 --- a/builtin/docker/registry_docker.go +++ b/builtin/docker/registry_docker.go @@ -115,7 +115,7 @@ func (r *Registry) pushWithDocker( return status.Errorf(codes.Internal, "unable to generate authentication info for registry: %s", err) } encodedAuth = base64.URLEncoding.EncodeToString(buf) - } else if (*r.config.Auth != Auth{}) { + } else if r.config.Auth != nil && *r.config.Auth != (Auth{}) { if authConfig.Hostname != "" { return status.Errorf(codes.InvalidArgument, "hostname not supported for registry") }