Check AF_UNIX path length (#7951)

This commit is contained in:
mehrdadn
2020-04-13 09:30:01 -07:00
committed by GitHub
parent c222d64ca1
commit 1b0f6fd558
3 changed files with 16 additions and 0 deletions
+7
View File
@@ -394,6 +394,7 @@ class Node:
socket_path (string): the socket file to prepare.
"""
result = socket_path
is_mac = sys.platform.startswith("darwin")
if sys.platform == "win32":
if socket_path is None:
result = "tcp://{}:{}".format(self._localhost,
@@ -407,6 +408,12 @@ class Node:
raise RuntimeError(
"Socket file {} exists!".format(socket_path))
try_to_create_directory(os.path.dirname(socket_path))
# Check socket path length to make sure it's short enough
maxlen = (104 if is_mac else 108) - 1 # sockaddr_un->sun_path
if len(result.split("://", 1)[-1].encode("utf-8")) > maxlen:
raise OSError("AF_UNIX path length cannot exceed "
"{} bytes: {!r}".format(maxlen, result))
return result
def start_reaper_process(self):
+6
View File
@@ -72,6 +72,12 @@ def test_tempdir_commandline():
ignore_errors=True)
def test_tempdir_long_path():
temp_dir = os.path.join(ray.utils.get_user_temp_dir(), "z" * 108)
with pytest.raises(OSError):
ray.init(temp_dir=temp_dir) # path should be too long
def test_raylet_socket_name(shutdown_only):
ray.init(
raylet_socket_name=os.path.join(ray.utils.get_user_temp_dir(),