Skip to content

Commit 4117d56

Browse files
committed
http/client: Throw error early if .path given and non AF_UNIX family
1 parent c632603 commit 4117d56

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

http/client.lua

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,19 @@ end
123123

124124
local function connect(options, timeout)
125125
local family = options.family
126+
if family == nil then
127+
family = cs.AF_UNSPEC
128+
end
129+
126130
local path = options.path
131+
if path then
132+
if family == cs.AF_UNSPEC then
133+
family = cs.AF_UNIX
134+
elseif family ~= cs.AF_UNIX then
135+
error("cannot use .path with non-unix address family")
136+
end
137+
end
138+
127139
local host = options.host
128140
if not path and not http_util.is_ip(host) then
129141
local dns_resolver = options.dns_resolver or cqueues_dns.getpool()

spec/client_spec.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ describe("http.client module", function()
1515
local openssl_pkey = require "openssl.pkey"
1616
local openssl_ctx = require "openssl.ssl.context"
1717
local openssl_x509 = require "openssl.x509"
18+
it("throws error on invalid family+path combination", function()
19+
assert.has.errors(function()
20+
client.connect{family = cs.AF_INET, path = "/somepath"}
21+
end)
22+
end)
1823
it("invalid network parameters return nil, err, errno", function()
1924
-- Invalid network parameters will return nil, err, errno
2025
local ok, err, errno = client.connect{host="127.0.0.1", port="invalid"}

0 commit comments

Comments
 (0)