Skip to content
Snippets Groups Projects
Commit 72b0ab6f authored by Dmitry E. Oboukhov's avatar Dmitry E. Oboukhov
Browse files

Fix crash socket.getaddrinfo with wrong options. #364

parent 414a5c15
No related branches found
No related tags found
No related merge requests found
......@@ -826,7 +826,7 @@ local function getaddrinfo(host, port, timeout, opts)
if opts.type ~= nil then
local itype = get_ivalue(internal.SO_TYPE, opts.type)
if itype == nil then
self._errno = box.errno.EINVAL
box.errno(box.errno.EINVAL)
return nil
end
ga_opts.type = itype
......@@ -835,7 +835,7 @@ local function getaddrinfo(host, port, timeout, opts)
if opts.family ~= nil then
local ifamily = get_ivalue(internal.DOMAIN, opts.family)
if ifamily == nil then
self._errno = box.errno.EINVAL
box.errno(box.errno.EINVAL)
return nil
end
ga_opts.family = ifamily
......@@ -844,7 +844,7 @@ local function getaddrinfo(host, port, timeout, opts)
if opts.protocol ~= nil then
local p = ffi.C.getprotobyname(opts.protocol)
if p == nil then
self._errno = box.errno(box.errno.EINVAL)
box.errno(box.errno.EINVAL)
return nil
end
ga_opts.protocol = p.p_proto
......@@ -854,20 +854,14 @@ local function getaddrinfo(host, port, timeout, opts)
ga_opts.flags =
get_iflags(internal.AI_FLAGS, opts.flags)
if ga_opts.flags == nil then
self._errno = box.errno()
box.errno(box.errno.EINVAL)
return nil
end
end
end
local r = internal.getaddrinfo(host, port, timeout, ga_opts)
if r == nil then
self._errno = box.errno()
else
self._errno = nil
end
return r
return internal.getaddrinfo(host, port, timeout, ga_opts)
end
local soname_mt = {
......
......@@ -1187,3 +1187,19 @@ lua box.cjson.encode{ box.socket.tcp_connect('test:test@localhost:3303') == nil,
---
- [true,"Invalid argument"]
...
lua box.socket.getaddrinfo('host', 'port', { type = 'WRONG' }) == nil and box.errno() == box.errno.EINVAL
---
- true
...
lua box.socket.getaddrinfo('host', 'port', { family = 'WRONG' }) == nil and box.errno() == box.errno.EINVAL
---
- true
...
lua box.socket.getaddrinfo('host', 'port', { protocol = 'WRONG' }) == nil and box.errno() == box.errno.EINVAL
---
- true
...
lua box.socket.getaddrinfo('host', 'port', { flags = 'WRONG' }) == nil and box.errno() == box.errno.EINVAL
---
- true
...
......@@ -388,3 +388,9 @@ if os.path.exists(path):
exec admin "lua box.cjson.encode{ box.socket.tcp_connect('test:test@localhost:3303') == nil, box.errno.strerror() }"
exec admin "lua box.socket.getaddrinfo('host', 'port', { type = 'WRONG' }) == nil and box.errno() == box.errno.EINVAL"
exec admin "lua box.socket.getaddrinfo('host', 'port', { family = 'WRONG' }) == nil and box.errno() == box.errno.EINVAL"
exec admin "lua box.socket.getaddrinfo('host', 'port', { protocol = 'WRONG' }) == nil and box.errno() == box.errno.EINVAL"
exec admin "lua box.socket.getaddrinfo('host', 'port', { flags = 'WRONG' }) == nil and box.errno() == box.errno.EINVAL"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment