Skip to content

Commit 35ce84b

Browse files
committed
http/client: Only allow '.bind' to be a string
1 parent e4c8cb6 commit 35ce84b

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

http/client.lua

+19-1
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,30 @@ local function negotiate(s, options, timeout)
8484
end
8585

8686
local function connect(options, timeout)
87+
local bind = options.bind
88+
if bind ~= nil then
89+
assert(type(bind) == "string")
90+
local bind_address, bind_port = bind:match("^(.-):(%d+)$")
91+
if bind_address then
92+
bind_port = tonumber(bind_port, 10)
93+
else
94+
bind_address = bind
95+
end
96+
local ipv6 = bind_address:match("^%[([:%x]+)%]$")
97+
if ipv6 then
98+
bind_address = ipv6
99+
end
100+
bind = {
101+
address = bind_address;
102+
port = bind_port;
103+
}
104+
end
87105
local s, err, errno = ca.fileresult(cs.connect {
88106
family = options.family;
89107
host = options.host;
90108
port = options.port;
91109
path = options.path;
92-
bind = options.bind;
110+
bind = bind;
93111
sendname = false;
94112
v6only = options.v6only;
95113
nodelay = true;

0 commit comments

Comments
 (0)