Skip to content

Commit 018abc1

Browse files
committed
Saner check for socket type/is_tcp
1 parent 171d78a commit 018abc1

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

‎lib/resty/shell.lua

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,19 @@ function shell.execute(cmd, args)
1919
local input_data = args and args.data or ""
2020
local socket = args and args.socket or default_socket
2121

22-
local is_tcp = true
23-
if (find(socket, "unix:", 1, true)) then
24-
is_tcp = false
25-
end
22+
local is_tcp
23+
24+
if (type(socket) == 'table') then
25+
if (socket.host and socket.port) then
26+
is_tcp = true
27+
else
28+
return -3, nil, 'invalid socket table options passed'
29+
end
30+
elseif (type(socket) == 'string') then
31+
is_tcp = false
32+
else
33+
return -3, nil, 'socket was not a table with tcp options or a string'
34+
end
2635

2736
local sock = tcp()
2837
local ok, err

0 commit comments

Comments
 (0)