Skip to content

Commit f2d4433

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

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

src/pipe_wrap.cc

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,10 @@ 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 = uv_pipe_bind2(&wrap->handle_,
166+
*name,
167+
name.length(),
168+
UV_PIPE_NO_TRUNCATE);
166169
args.GetReturnValue().Set(err);
167170
}
168171

@@ -226,7 +229,12 @@ void PipeWrap::Connect(const FunctionCallbackInfo<Value>& args) {
226229
ConnectWrap* req_wrap =
227230
new ConnectWrap(env, req_wrap_obj, AsyncWrap::PROVIDER_PIPECONNECTWRAP);
228231
int err = req_wrap->Dispatch(
229-
uv_pipe_connect2, &wrap->handle_, *name, name.length(), 0, AfterConnect);
232+
uv_pipe_connect2,
233+
&wrap->handle_,
234+
*name,
235+
name.length(),
236+
UV_PIPE_NO_TRUNCATE,
237+
AfterConnect);
230238
if (err) {
231239
delete req_wrap;
232240
} else {
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
const pipePath = `${tmpdir.path}/${'x'.repeat(1000)}.sock`;
10+
11+
const server = net.createServer(common.mustNotCall())
12+
.listen(pipePath)
13+
// It may work on some operating systems
14+
.on('listening', () => {
15+
// The socket file must exsit
16+
assert.ok(fs.existsSync(pipePath));
17+
server.close();
18+
})
19+
.on('error', (error) => {
20+
assert.ok(error.code === 'EINVAL');
21+
net.connect(pipePath)
22+
.on('error', common.mustCall((error) => {
23+
assert.ok(error.code === 'EINVAL');
24+
}));
25+
});

0 commit comments

Comments
 (0)