From 8735574dfe499cb72d82e399d0c16cce996631a0 Mon Sep 17 00:00:00 2001 From: theanarkh Date: Tue, 21 Nov 2023 20:21:57 +0800 Subject: [PATCH] net: check pipe mode and path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/50770 Reviewed-By: Vinícius Lourenço Claro Cardoso Reviewed-By: James M Snell --- lib/net.js | 6 ++++ test/parallel/test-pipe-abstract-socket.js | 34 ++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 test/parallel/test-pipe-abstract-socket.js diff --git a/lib/net.js b/lib/net.js index 02bc1cd713770e..a7e1dbb3f524a5 100644 --- a/lib/net.js +++ b/lib/net.js @@ -2014,6 +2014,12 @@ Server.prototype.listen = function(...args) { // (path[, backlog][, cb]) or (options[, cb]) // where path or options.path is a UNIX domain socket or Windows pipe if (options.path && isPipeName(options.path)) { + // We can not call fchmod on abstract unix socket + if (options.path[0] === '\0' && + (options.readableAll || options.writableAll)) { + const msg = 'can not set readableAll or writableAllt to true when path is abstract unix socket'; + throw new ERR_INVALID_ARG_VALUE('options', options, msg); + } const pipeName = this._pipeName = options.path; backlog = options.backlog || backlogFromArgs; listenInCluster(this, diff --git a/test/parallel/test-pipe-abstract-socket.js b/test/parallel/test-pipe-abstract-socket.js new file mode 100644 index 00000000000000..baf76d6b82cf59 --- /dev/null +++ b/test/parallel/test-pipe-abstract-socket.js @@ -0,0 +1,34 @@ +'use strict'; +const common = require('../common'); +const assert = require('assert'); +const net = require('net'); + +if (!common.isLinux) common.skip(); + +const path = '\0abstract'; +const message = /can not set readableAll or writableAllt to true when path is abstract unix socket/; + +assert.throws(() => { + const server = net.createServer(common.mustNotCall()); + server.listen({ + path, + readableAll: true + }); +}, message); + +assert.throws(() => { + const server = net.createServer(common.mustNotCall()); + server.listen({ + path, + writableAll: true + }); +}, message); + +assert.throws(() => { + const server = net.createServer(common.mustNotCall()); + server.listen({ + path, + readableAll: true, + writableAll: true + }); +}, message);