Skip to content

Commit

Permalink
src: add UV_PIPE_NO_TRUNCATE for bind in pipe_wrap.cc
Browse files Browse the repository at this point in the history
  • Loading branch information
theanarkh committed Apr 3, 2024
1 parent 4e9ce7c commit f2d4433
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/pipe_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,10 @@ void PipeWrap::Bind(const FunctionCallbackInfo<Value>& args) {
PipeWrap* wrap;
ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder());
node::Utf8Value name(args.GetIsolate(), args[0]);
int err = uv_pipe_bind2(&wrap->handle_, *name, name.length(), 0);
int err = uv_pipe_bind2(&wrap->handle_,
*name,
name.length(),
UV_PIPE_NO_TRUNCATE);
args.GetReturnValue().Set(err);
}

Expand Down Expand Up @@ -226,7 +229,12 @@ void PipeWrap::Connect(const FunctionCallbackInfo<Value>& args) {
ConnectWrap* req_wrap =
new ConnectWrap(env, req_wrap_obj, AsyncWrap::PROVIDER_PIPECONNECTWRAP);
int err = req_wrap->Dispatch(
uv_pipe_connect2, &wrap->handle_, *name, name.length(), 0, AfterConnect);
uv_pipe_connect2,
&wrap->handle_,
*name,
name.length(),
UV_PIPE_NO_TRUNCATE,
AfterConnect);
if (err) {
delete req_wrap;
} else {
Expand Down
25 changes: 25 additions & 0 deletions test/parallel/test-net-pipe-with-long-path.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const net = require('net');
const fs = require('fs');
const tmpdir = require('../common/tmpdir');
tmpdir.refresh();

const pipePath = `${tmpdir.path}/${'x'.repeat(1000)}.sock`;

const server = net.createServer(common.mustNotCall())
.listen(pipePath)
// It may work on some operating systems
.on('listening', () => {
// The socket file must exsit
assert.ok(fs.existsSync(pipePath));
server.close();
})
.on('error', (error) => {
assert.ok(error.code === 'EINVAL');
net.connect(pipePath)
.on('error', common.mustCall((error) => {
assert.ok(error.code === 'EINVAL');
}));
});

0 comments on commit f2d4433

Please sign in to comment.