Address review: bind test sockets to localhost instead of all interfaces

Fix CodeQL security warning by binding test helper sockets to
"localhost" instead of "" (all interfaces). These sockets are only
used for finding a free port for torch distributed init in tests.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Alexander Matveev <alexm-redhat@dgx-b200-02.mgmt.accl-001.lab.rdu2.dc.redhat.com>
This commit is contained in:
Alexander Matveev
2026-06-15 18:09:24 -04:00
co-authored by Claude Opus 4.6
parent c55216ebbf
commit e0601e1b94
2 changed files with 2 additions and 2 deletions
+1 -1
View File
@@ -19,7 +19,7 @@ import torch.distributed as dist
def find_free_port() -> int:
"""Find a free TCP port for distributed init."""
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.bind(("", 0))
s.bind(("localhost", 0))
return s.getsockname()[1]
+1 -1
View File
@@ -51,7 +51,7 @@ def _find_free_port() -> int:
import socket
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.bind(("", 0))
s.bind(("localhost", 0))
return s.getsockname()[1]