Skip to content

Commit a8b0389

Browse files
ImeevMATotktonada
authored andcommitted
Correctly check unix socket path length
Before this patch, the length of the entire URI was compared to the maximum Unix socket path length. This is problematic because the URI includes more than just the path, such as the login and parameters. After this patch, only the path will be checked. Closes #341
1 parent 7b6f167 commit a8b0389

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
* Fixed incorrent unix socket path length check (gh-341).
6+
37
## 1.0.0
48

59
- Extend `server.lua` API:

luatest/server.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,13 @@ function Server:initialize()
156156
self.net_box_uri = 'localhost:' .. self.net_box_port
157157
end
158158
end
159-
if uri.parse(self.net_box_uri).host == 'unix/' then
159+
local parsed_net_box_uri = uri.parse(self.net_box_uri)
160+
if parsed_net_box_uri.host == 'unix/' then
160161
-- Linux uses max 108 bytes for Unix domain socket paths, which means a 107 characters
161162
-- string ended by a null terminator. Other systems use 104 bytes and 103 characters strings.
162163
local max_unix_socket_path = {linux = 107, other = 103}
163164
local system = os.execute('[ $(uname) = Linux ]') == 0 and 'linux' or 'other'
164-
if self.net_box_uri:len() > max_unix_socket_path[system] then
165+
if parsed_net_box_uri.unix:len() > max_unix_socket_path[system] then
165166
error(('Net box URI must be <= max Unix domain socket path length (%d chars)')
166167
:format(max_unix_socket_path[system]))
167168
end

test/server_test.lua

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,31 @@ g.test_max_unix_socket_path_exceeded = function()
296296
)
297297
end
298298

299+
g.test_unix_socket_not_include_uri_fields = function()
300+
local max_unix_socket_path = {linux = 107, other = 103}
301+
local system = os.execute('[ $(uname) = Linux ]') == 0 and 'linux' or
302+
'other'
303+
local workdir = fio.pathjoin(datadir, 'unix_socket')
304+
fio.mktree(workdir)
305+
local workdir_len = string.len(workdir)
306+
local socket_name_len = max_unix_socket_path[system] + 1 - workdir_len
307+
local socket_name = string.format('test_socket%s.sock',
308+
string.rep('t', socket_name_len - 18))
309+
local socket_path = fio.pathjoin(workdir, socket_name)
310+
t.assert_equals(string.len(socket_path), max_unix_socket_path[system])
311+
local net_box_uri = 'unix/:' .. socket_path .. '?three=1&four=2'
312+
local s = Server:new({
313+
command = command,
314+
workdir = workdir,
315+
net_box_uri = net_box_uri,
316+
http_port = 0, -- unused
317+
})
318+
s:start()
319+
t.helpers.retrying({}, function() s:connect_net_box() end)
320+
t.assert_equals(s:exec(function() return box.cfg.listen end), net_box_uri)
321+
s:stop()
322+
end
323+
299324
g.test_server_start_with_coverage_enabled = function()
300325
t.skip_if(server.coverage_report, 'Coverage is already enabled. Nothing to test')
301326
server:restart({coverage_report = true})

0 commit comments

Comments
 (0)