Skip to content

Commit e083fc7

Browse files
authored
Fixing security concern (#1857)
fixing get_free_port() function
1 parent b0a445b commit e083fc7

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/ansys/fluent/core/utils/networking.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ def get_free_port() -> int:
1919
int
2020
port number
2121
"""
22-
sock = socket.socket()
23-
sock.bind(("", 0))
24-
return sock.getsockname()[1]
22+
with socket.socket() as s:
23+
s.bind(("localhost", 0))
24+
free_port = s.getsockname()[1]
25+
return free_port
2526

2627

2728
class _HealthServicer(health_pb2_grpc.HealthServicer):

0 commit comments

Comments
 (0)