Skip to content

Commit 4e06896

Browse files
committed
src: add UV_PIPE_NO_TRUNCATE for bind in pipe_wrap.cc
1 parent 4e9ce7c commit 4e06896

File tree

3 files changed

+49
-8
lines changed

3 files changed

+49
-8
lines changed

doc/api/net.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ sockets on other operating systems.
2929
[`socket.connect()`][] take a `path` parameter to identify IPC endpoints.
3030

3131
On Unix, the local domain is also known as the Unix domain. The path is a
32-
file system pathname. It gets truncated to an OS-dependent length of
33-
`sizeof(sockaddr_un.sun_path) - 1`. Typical values are 107 bytes on Linux and
34-
103 bytes on macOS. If a Node.js API abstraction creates the Unix domain socket,
35-
it will unlink the Unix domain socket as well. For example,
36-
[`net.createServer()`][] may create a Unix domain socket and
32+
file system pathname. It will throw an error when the length of pathname is
33+
greater than the length of `sizeof(sockaddr_un.sun_path)`. Typical values are
34+
107 bytes on Linux and 103 bytes on macOS. If a Node.js API abstraction creates
35+
the Unix domain socket, it will unlink the Unix domain socket as well. For
36+
example, [`net.createServer()`][] may create a Unix domain socket and
3737
[`server.close()`][] will unlink it. But if a user creates the Unix domain
3838
socket outside of these abstractions, the user will need to remove it. The same
3939
applies when a Node.js API creates a Unix domain socket but the program then

src/pipe_wrap.cc

+8-3
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@ void PipeWrap::Bind(const FunctionCallbackInfo<Value>& args) {
162162
PipeWrap* wrap;
163163
ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder());
164164
node::Utf8Value name(args.GetIsolate(), args[0]);
165-
int err = uv_pipe_bind2(&wrap->handle_, *name, name.length(), 0);
165+
int err =
166+
uv_pipe_bind2(&wrap->handle_, *name, name.length(), UV_PIPE_NO_TRUNCATE);
166167
args.GetReturnValue().Set(err);
167168
}
168169

@@ -225,8 +226,12 @@ void PipeWrap::Connect(const FunctionCallbackInfo<Value>& args) {
225226

226227
ConnectWrap* req_wrap =
227228
new ConnectWrap(env, req_wrap_obj, AsyncWrap::PROVIDER_PIPECONNECTWRAP);
228-
int err = req_wrap->Dispatch(
229-
uv_pipe_connect2, &wrap->handle_, *name, name.length(), 0, AfterConnect);
229+
int err = req_wrap->Dispatch(uv_pipe_connect2,
230+
&wrap->handle_,
231+
*name,
232+
name.length(),
233+
UV_PIPE_NO_TRUNCATE,
234+
AfterConnect);
230235
if (err) {
231236
delete req_wrap;
232237
} else {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const net = require('net');
5+
const fs = require('fs');
6+
const tmpdir = require('../common/tmpdir');
7+
tmpdir.refresh();
8+
9+
// Test UV_PIPE_NO_TRUNCATE
10+
11+
// See pipe_overlong_path in https://github.com/libuv/libuv/blob/master/test/test-pipe-bind-error.c
12+
if (common.isWindows) {
13+
common.skip('UV_PIPE_NO_TRUNCATE is not supported on window');
14+
}
15+
16+
// See https://github.com/libuv/libuv/issues/4231
17+
const pipePath = `${tmpdir.path}/${'x'.repeat(10000)}.sock`;
18+
19+
const server = net.createServer()
20+
.listen(pipePath)
21+
// It may work on some operating systems
22+
.on('listening', () => {
23+
// The socket file must exsit
24+
assert.ok(fs.existsSync(pipePath));
25+
const socket = net.connect(pipePath, common.mustCall(() => {
26+
socket.destroy();
27+
server.close();
28+
}));
29+
})
30+
.on('error', (error) => {
31+
assert.ok(error.code === 'EINVAL', error.message);
32+
net.connect(pipePath)
33+
.on('error', common.mustCall((error) => {
34+
assert.ok(error.code === 'EINVAL', error.message);
35+
}));
36+
});

0 commit comments

Comments
 (0)