Compare commits
2 Commits
faf6b8e93e
...
ca5c7feb9f
Author | SHA1 | Date | |
---|---|---|---|
![]() |
ca5c7feb9f | ||
![]() |
fdb8745ee0 |
@@ -62,13 +62,11 @@ func sanitizeAddress(addr string) string {
|
||||
|
||||
func validateAddressFormat(addr string) error {
|
||||
host, _, err := net.SplitHostPort(addr)
|
||||
if err != nil {
|
||||
// If SplitHostPort fails, it means addr is not in host:port format
|
||||
host = addr
|
||||
}
|
||||
if host != "" {
|
||||
if err == nil {
|
||||
// Successfully split host:port, use just the host part
|
||||
addr = host
|
||||
}
|
||||
|
||||
if len(addr) > MaxAddressLength || len(addr) < MinAddressLength {
|
||||
return fmt.Errorf("invalid address length: got %d, want between %d and %d",
|
||||
len(addr), MinAddressLength, MaxAddressLength)
|
||||
|
@@ -61,7 +61,12 @@ func (c *samClient) generateDestination(ctx context.Context, keyType string) (*I
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("connecting to SAM bridge: %w", err)
|
||||
}
|
||||
defer conn.Close()
|
||||
// Ensure connection is always closed, even on error paths
|
||||
defer func() {
|
||||
if closeErr := conn.Close(); closeErr != nil {
|
||||
log.WithError(closeErr).Debug("Error closing SAM connection")
|
||||
}
|
||||
}()
|
||||
|
||||
if err := c.handshake(ctx, conn); err != nil {
|
||||
return nil, fmt.Errorf("SAM handshake failed: %w", err)
|
||||
|
Reference in New Issue
Block a user