From 3914c4c018afa48168804209abc5ec08285d1987 Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Fri, 26 Jun 2015 16:40:10 +0100 Subject: [PATCH] Enforce maximum length on proxy hostname derivation --- proxy/create_container_interceptor.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/proxy/create_container_interceptor.go b/proxy/create_container_interceptor.go index db9433ef..b7d8d0c2 100644 --- a/proxy/create_container_interceptor.go +++ b/proxy/create_container_interceptor.go @@ -13,6 +13,8 @@ import ( "github.com/weaveworks/weave/nameserver" ) +const MaxDockerHostname = 64 + type createContainerInterceptor struct{ proxy *Proxy } type createContainerRequestBody struct { @@ -110,9 +112,14 @@ func (i *createContainerInterceptor) setWeaveDNS(container *createContainerReque name := r.URL.Query().Get("name") if container.Hostname == "" && name != "" { - container.Hostname = name // Strip trailing period because it's unusual to see it used on the end of a host name - container.Domainname = strings.TrimSuffix(dnsDomain, ".") + trimmedDNSDomain := strings.TrimSuffix(dnsDomain, ".") + if len(name)+1+len(trimmedDNSDomain) > MaxDockerHostname { + Warning.Printf("Container name [%s] too long to be used as hostname", name) + } else { + container.Hostname = name + container.Domainname = trimmedDNSDomain + } } if len(container.HostConfig.DNSSearch) == 0 {