From f097bb3241db54b8c515b23ae6f3e6a9c773d787 Mon Sep 17 00:00:00 2001 From: Ivan Date: Sun, 9 Nov 2025 00:05:36 -0600 Subject: [PATCH] security: use net.JoinHostPort instead of fmt.Sprintf --- pkg/interfaces/tcp.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/interfaces/tcp.go b/pkg/interfaces/tcp.go index 4827376..2e146e2 100644 --- a/pkg/interfaces/tcp.go +++ b/pkg/interfaces/tcp.go @@ -333,7 +333,7 @@ func (tc *TCPClientInterface) reconnect() { // Log reconnection attempt fmt.Printf("Failed to reconnect to %s (attempt %d/%d): %v\n", - addr, retries+1, tc.maxReconnectTries, err) + net.JoinHostPort(tc.targetAddr, fmt.Sprintf("%d", tc.targetPort)), retries+1, tc.maxReconnectTries, err) // Wait with exponential backoff time.Sleep(backoff) @@ -354,7 +354,7 @@ func (tc *TCPClientInterface) reconnect() { // If we've exhausted all retries, perform final teardown tc.teardown() fmt.Printf("Failed to reconnect to %s after %d attempts\n", - fmt.Sprintf("%s:%d", tc.targetAddr, tc.targetPort), tc.maxReconnectTries) + net.JoinHostPort(tc.targetAddr, fmt.Sprintf("%d", tc.targetPort)), tc.maxReconnectTries) } func (tc *TCPClientInterface) Enable() { @@ -562,7 +562,7 @@ func (ts *TCPServerInterface) Start() error { ts.mutex.Lock() defer ts.mutex.Unlock() - addr := fmt.Sprintf("%s:%d", ts.bindAddr, ts.bindPort) + addr := net.JoinHostPort(ts.bindAddr, fmt.Sprintf("%d", ts.bindPort)) listener, err := net.Listen("tcp", addr) if err != nil { return fmt.Errorf("failed to start TCP server: %w", err)