1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #1393 from sanimej/2782

Relax SRV name validation and fix external SRV query handling
This commit is contained in:
Jana Radhakrishnan 2016-08-15 16:37:29 -07:00 committed by GitHub
commit 30b53a73c1
3 changed files with 11 additions and 8 deletions

View file

@ -411,10 +411,10 @@ func TestSRVServiceQuery(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
// Try resolving a service name with invalid protocol, should fail.. // Service name with invalid protocol name. Should fail without error
_, _, err = ep.Info().Sandbox().ResolveService("_http._icmp.web.swarm") _, ip, err = ep.Info().Sandbox().ResolveService("_http._icmp.web.swarm")
if err == nil { if len(ip) != 0 {
t.Fatal(err) t.Fatal("Valid response for invalid service name")
} }
} }

View file

@ -255,6 +255,9 @@ func (r *resolver) handleSRVQuery(svc string, query *dns.Msg) (*dns.Msg, error)
if err != nil { if err != nil {
return nil, err return nil, err
} }
if len(srv) == 0 {
return nil, nil
}
if len(srv) != len(ip) { if len(srv) != len(ip) {
return nil, fmt.Errorf("invalid reply for SRV query %s", svc) return nil, fmt.Errorf("invalid reply for SRV query %s", svc)
} }

View file

@ -444,16 +444,16 @@ func (sb *sandbox) ResolveService(name string) ([]*net.SRV, []net.IP, error) {
log.Debugf("Service name To resolve: %v", name) log.Debugf("Service name To resolve: %v", name)
// There are DNS implementaions that allow SRV queries for names not in
// the format defined by RFC 2782. Hence specific validations checks are
// not done
parts := strings.Split(name, ".") parts := strings.Split(name, ".")
if len(parts) < 3 { if len(parts) < 3 {
return nil, nil, fmt.Errorf("invalid service name, %s", name) return nil, nil, nil
} }
portName := parts[0] portName := parts[0]
proto := parts[1] proto := parts[1]
if proto != "_tcp" && proto != "_udp" {
return nil, nil, fmt.Errorf("invalid protocol in service, %s", name)
}
svcName := strings.Join(parts[2:], ".") svcName := strings.Join(parts[2:], ".")
for _, ep := range sb.getConnectedEndpoints() { for _, ep := range sb.getConnectedEndpoints() {