diff --git a/contrib/registry/consul/client.go b/contrib/registry/consul/client.go index 471db8b0f10..01279964707 100644 --- a/contrib/registry/consul/client.go +++ b/contrib/registry/consul/client.go @@ -38,7 +38,7 @@ type Client struct { heartbeat bool // deregisterCriticalServiceAfter time interval in seconds deregisterCriticalServiceAfter int - // serviceChecks user custom checks + // serviceChecks user custom checks serviceChecks api.AgentServiceChecks // tags is service tags tags []string @@ -163,7 +163,10 @@ func (c *Client) Register(ctx context.Context, svc *registry.ServiceInstance, en return err } addr := raw.Hostname() - port, _ := strconv.ParseUint(raw.Port(), 10, 16) + port, err := strconv.ParseUint(raw.Port(), 10, 16) + if err != nil || port == 0 { + return fmt.Errorf("invalid port in endpoint: %q", endpoint) + } checkAddresses = append(checkAddresses, net.JoinHostPort(addr, strconv.FormatUint(port, 10))) addresses[raw.Scheme] = api.ServiceAddress{Address: endpoint, Port: int(port)} @@ -181,7 +184,7 @@ func (c *Client) Register(ctx context.Context, svc *registry.ServiceInstance, en } if len(checkAddresses) > 0 { host, portRaw, _ := net.SplitHostPort(checkAddresses[0]) - port, _ := strconv.ParseInt(portRaw, 10, 32) + port, _ := strconv.ParseUint(portRaw, 10, 16) asr.Address = host asr.Port = int(port) }