From f2d4433a95d0b952bddb69478a7c2430c29b37ae Mon Sep 17 00:00:00 2001 From: theanarkh Date: Wed, 3 Apr 2024 21:37:12 +0800 Subject: [PATCH] src: add UV_PIPE_NO_TRUNCATE for bind in pipe_wrap.cc --- src/pipe_wrap.cc | 12 +++++++-- test/parallel/test-net-pipe-with-long-path.js | 25 +++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 test/parallel/test-net-pipe-with-long-path.js diff --git a/src/pipe_wrap.cc b/src/pipe_wrap.cc index 3f7cf26709e57f..7afac60350bae5 100644 --- a/src/pipe_wrap.cc +++ b/src/pipe_wrap.cc @@ -162,7 +162,10 @@ void PipeWrap::Bind(const FunctionCallbackInfo& 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); } @@ -226,7 +229,12 @@ void PipeWrap::Connect(const FunctionCallbackInfo& 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 { diff --git a/test/parallel/test-net-pipe-with-long-path.js b/test/parallel/test-net-pipe-with-long-path.js new file mode 100644 index 00000000000000..c1f92c926fdbb8 --- /dev/null +++ b/test/parallel/test-net-pipe-with-long-path.js @@ -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'); + })); + });