From acd39bb5d4ba9a4c9604559f43123b512e8c2af6 Mon Sep 17 00:00:00 2001 From: Alfonso Acosta Date: Wed, 24 Apr 2019 10:51:55 +0100 Subject: [PATCH] Handle SplitHostPort errors --- registry/client_factory.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/registry/client_factory.go b/registry/client_factory.go index af2925b6d..12265298d 100644 --- a/registry/client_factory.go +++ b/registry/client_factory.go @@ -93,16 +93,21 @@ attemptChallenge: } func (f *RemoteClientFactory) ClientFor(repo image.CanonicalName, creds Credentials) (Client, error) { - repoHost, _, err := net.SplitHostPort(repo.Domain) - if err != nil { - return nil, err + repoHosts := []string{repo.Domain} + // allow the insecure hosts list to contain hosts with or without the port + repoHostWithoutPort, _, err := net.SplitHostPort(repo.Domain) + if err == nil { + // parsing fails if no port is present + repoHosts = append(repoHosts, repoHostWithoutPort) } insecure := false +insecureCheckLoop: for _, h := range f.InsecureHosts { - // allow the insecure hosts list to contain hosts with or without the port - if repoHost == h || repo.Domain == h { - insecure = true - break + for _, repoHost := range repoHosts { + if h == repoHost { + insecure = true + break insecureCheckLoop + } } }