Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions contrib/registry/consul/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

// used to control heartbeat
Expand Down Expand Up @@ -161,7 +161,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)}
Expand All @@ -175,7 +178,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)
Copy link

Copilot AI Jul 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error from strconv.ParseUint is ignored here; consider handling parse errors to avoid silently defaulting to port 0, similar to the validation added above.

Suggested change
port, _ := strconv.ParseUint(portRaw, 10, 16)
port, err := strconv.ParseUint(portRaw, 10, 16)
if err != nil || port == 0 {
return fmt.Errorf("invalid port in check address: %q", checkAddresses[0])
}

Copilot uses AI. Check for mistakes.
asr.Address = host
asr.Port = int(port)
}
Expand Down
Loading