Avoid nil dereference if passing a nil resolver

Signed-off-by: Antonio Gamez Diaz <agamez@vmware.com>
pull/11129/head
Antonio Gamez Diaz 1 year ago
parent 197d1defbf
commit 3607cd7110
No known key found for this signature in database
GPG Key ID: 96108DED40068D35

@ -88,8 +88,15 @@ func NewClient(options ...ClientOption) (*Client, error) {
client.authorizer = authClient
}
if client.resolver == nil {
resolverFn := client.resolver // copy for avoiding recursive call
client.resolver = func(ref registry.Reference) (remotes.Resolver, error) {
if resolverFn != nil {
// validate if the resolverFn returns a valid resolver
if resolver, err := resolverFn(ref); resolver != nil && err == nil {
return resolver, nil
}
}
headers := http.Header{}
headers.Set("User-Agent", version.GetUserAgent())
dockerClient, ok := client.authorizer.(*dockerauth.Client)
@ -119,7 +126,6 @@ func NewClient(options ...ClientOption) (*Client, error) {
}
return resolver, nil
}
}
// allocate a cache if option is set
var cache registryauth.Cache

Loading…
Cancel
Save