Skip to content

Commit fcbfdc0

Browse files
seandewarsqueek502
authored andcommitted
fix: handle return value of uv_pipe_connect2
The missing check meant that no error was propagated when it returned UV_EINVAL. This notably produced no error when specifying an invalid name, and made specifying UV_PIPE_NO_TRUNCATE ineffective. This was likely missed out because libuv's documented return value for uv_pipe_connect2 incorrectly stated that it returns void, not int; that's since been fixed.
1 parent 5e97827 commit fcbfdc0

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/pipe.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,12 @@ static int luv_pipe_connect2(lua_State* L) {
9898
int ref = luv_check_continuation(L, 4);
9999
uv_connect_t* req = (uv_connect_t*)lua_newuserdata(L, uv_req_size(UV_CONNECT));
100100
req->data = luv_setup_req(L, ctx, ref);
101-
uv_pipe_connect2(req, handle, name, namelen, flags, luv_connect_cb);
101+
int ret = uv_pipe_connect2(req, handle, name, namelen, flags, luv_connect_cb);
102+
if (ret < 0) {
103+
luv_cleanup_req(L, (luv_req_t*)req->data);
104+
lua_pop(L, 1);
105+
return luv_error(L, ret);
106+
}
102107
return 1;
103108
}
104109
#endif

tests/test-pipe.lua

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,17 @@ return require('lib/tap')(function (test)
155155
end
156156
end, "1.46.0")
157157

158+
test("pipe connect2 error", function (print, p, expect, uv)
159+
local pipe = assert(uv.new_pipe(false))
160+
161+
local ran_cb = false
162+
local _, err = pipe:connect2("", nil, function()
163+
ran_cb = true
164+
end)
165+
assert(err:match("^EINVAL:"))
166+
uv.run()
167+
assert(not ran_cb)
168+
169+
pipe:close()
170+
end, "1.46.0")
158171
end)

0 commit comments

Comments
 (0)