diff --git a/src/nvim/event/socket.c b/src/nvim/event/socket.c index 46cb14e4d9..7ad7a824a4 100644 --- a/src/nvim/event/socket.c +++ b/src/nvim/event/socket.c @@ -169,7 +169,8 @@ int socket_watcher_start(SocketWatcher *watcher, int backlog, socket_cb cb) } uv_freeaddrinfo(watcher->uv.tcp.addrinfo); } else { - result = uv_pipe_bind(&watcher->uv.pipe.handle, watcher->addr); + result = uv_pipe_bind2(&watcher->uv.pipe.handle, watcher->addr, strlen(watcher->addr), + UV_PIPE_NO_TRUNCATE); // If bind failed with EACCES/EADDRINUSE, check if socket is stale if (result == UV_EACCES || result == UV_EADDRINUSE) { @@ -196,7 +197,8 @@ int socket_watcher_start(SocketWatcher *watcher, int backlog, socket_cb cb) watcher->stream->data = watcher; // Retry bind with fresh handle - result = uv_pipe_bind(&watcher->uv.pipe.handle, watcher->addr); + result = uv_pipe_bind2(&watcher->uv.pipe.handle, watcher->addr, strlen(watcher->addr), + UV_PIPE_NO_TRUNCATE); } } else { // Socket is alive - this is a real error diff --git a/test/functional/core/server_spec.lua b/test/functional/core/server_spec.lua index d1ab9e3cea..efe5dcc689 100644 --- a/test/functional/core/server_spec.lua +++ b/test/functional/core/server_spec.lua @@ -364,6 +364,15 @@ describe('startup --listen', function() ('nvim.*: Failed to %%-%%-listen: [^:]+ already [^:]+: "%s"'):format(vim.pesc(in_use)) ) _test({ '--listen', '/' }, nil, 'nvim.*: Failed to %-%-listen: [^:]+: "/"') + if not is_os('win') then + -- Too-long path is rejected, not silently truncated. #38623 + local too_long = './Xtest-listen-' .. ('x'):rep(192) + _test( + { '--listen', too_long }, + nil, + ('nvim.*: Failed to %%-%%-listen: invalid argument: "%s"'):format(vim.pesc(too_long)) + ) + end _test( { '--listen', 'https://example.com' }, nil, diff --git a/test/functional/options/defaults_spec.lua b/test/functional/options/defaults_spec.lua index 46056a917c..36bd00ab7c 100644 --- a/test/functional/options/defaults_spec.lua +++ b/test/functional/options/defaults_spec.lua @@ -376,8 +376,8 @@ describe('XDG defaults', function() if not is_os('win') then -- Broken XDG vars cause serverstart() to fail (except on Windows, where servernames are not -- informed by $XDG_STATE_HOME). - t.matches('Failed to start server: no such file or directory', t.pcall_err(fn.serverstart)) - assert_log('Failed to start server: no such file or directory: /X/X/X', testlog, 10) + t.matches('Failed to start server: invalid argument', t.pcall_err(fn.serverstart)) + assert_log('Failed to start server: invalid argument: /X/X/X', testlog, 10) end local vimruntime, libdir = vimruntime_and_libdir() @@ -962,6 +962,13 @@ describe('stdpath()', function() it('$NVIM_APPNAME relative path', function() local tmpdir = t.tmpname(false) t.mkdir(tmpdir) + -- Short runtime dir so the autogenerated server socket fits in sun_path even + -- when $TMPDIR is deep (otherwise the server fails to bind, see #38623). + local xdg_run = 'Xtest-appname-run' + mkdir(xdg_run) + finally(function() + rmdir(xdg_run) + end) clear({ args_rm = { '--listen' }, @@ -969,6 +976,7 @@ describe('stdpath()', function() NVIM_APPNAME = 'relative/appname', NVIM_LOG_FILE = testlog, TMPDIR = tmpdir, + XDG_RUNTIME_DIR = xdg_run, }, })