pipe: disallow listening on an IPC pipe

PR-URL: https://github.com/libuv/libuv/pull/2559
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
Reviewed-By: Saúl Ibarra Corretgé <s@saghul.net>
This commit is contained in:
Witold Kręcicki 2019-11-30 00:53:02 +01:00 committed by Saúl Ibarra Corretgé
parent 1ff8420661
commit a629688008
4 changed files with 18 additions and 3 deletions

View File

@ -24,6 +24,8 @@ Public members
.. c:member:: int uv_pipe_t.ipc
Whether this pipe is suitable for handle passing between processes.
Only a connected pipe that will be passing the handles should have this flag
set, not the listening pipe that uv_accept is called on.
.. seealso:: The :c:type:`uv_stream_t` members also apply.
@ -35,7 +37,9 @@ API
Initialize a pipe handle. The `ipc` argument is a boolean to indicate if
this pipe will be used for handle passing between processes (which may
change the bytes on the wire).
change the bytes on the wire). Only a connected pipe that will be
passing the handles should have this flag set, not the listening pipe
that uv_accept is called on.
.. c:function:: int uv_pipe_open(uv_pipe_t* handle, uv_file file)

View File

@ -95,6 +95,9 @@ int uv_pipe_listen(uv_pipe_t* handle, int backlog, uv_connection_cb cb) {
if (uv__stream_fd(handle) == -1)
return UV_EINVAL;
if (handle->ipc)
return UV_EINVAL;
#if defined(__MVS__) || defined(__PASE__)
/* On zOS, backlog=0 has undefined behaviour */
/* On IBMi PASE, backlog=0 leads to "Connection refused" error */

View File

@ -955,6 +955,10 @@ int uv_pipe_listen(uv_pipe_t* handle, int backlog, uv_connection_cb cb) {
return ERROR_NOT_SUPPORTED;
}
if (handle->ipc) {
return WSAEINVAL;
}
handle->flags |= UV_HANDLE_LISTENING;
INCREASE_ACTIVE_COUNT(loop, handle);
handle->stream.serv.connection_cb = cb;

View File

@ -218,8 +218,12 @@ static void send_listen_handles(uv_handle_type type,
}
else
ASSERT(0);
ASSERT(0 == uv_pipe_init(loop, &ctx.ipc_pipe, 1));
/* We need to initialize this pipe with ipc=0 - this is not a uv_pipe we'll
* be sending handles over, it's just for listening for new connections.
* If we accept a connection then the connected pipe must be initialized
* with ipc=1.
*/
ASSERT(0 == uv_pipe_init(loop, &ctx.ipc_pipe, 0));
ASSERT(0 == uv_pipe_bind(&ctx.ipc_pipe, IPC_PIPE_NAME));
ASSERT(0 == uv_listen((uv_stream_t*) &ctx.ipc_pipe, 128, ipc_connection_cb));