mirror of
https://github.com/wassname/ray.git
synced 2026-07-13 17:45:08 +08:00
Check AF_UNIX path length (#7951)
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -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(),
|
||||
|
||||
@@ -100,6 +100,9 @@ ParseUrlEndpoint(const std::string &endpoint, int default_port) {
|
||||
}
|
||||
if (scheme == "unix://") {
|
||||
#ifdef BOOST_ASIO_HAS_LOCAL_SOCKETS
|
||||
size_t maxlen = sizeof(sockaddr_un().sun_path) / sizeof(*sockaddr_un().sun_path) - 1;
|
||||
RAY_CHECK(address.size() <= maxlen)
|
||||
<< "AF_UNIX path length cannot exceed " << maxlen << " bytes: " << address;
|
||||
result = boost::asio::local::stream_protocol::endpoint(address);
|
||||
#else
|
||||
RAY_LOG(FATAL) << "UNIX-domain socket endpoints are not supported: " << endpoint;
|
||||
|
||||
Reference in New Issue
Block a user