Skip to content

Commit

Permalink
process: avoid using the same fd for ipc and stdio
Browse files Browse the repository at this point in the history
There is already a check in place to prevent stdin and the IPC
channel from sharing a file descriptor. This commit adds a
similar check to stdout and stderr.

Refs: libuv/libuv#1851
Refs: libuv/libuv#1897
PR-URL: #21466
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
cjihrig authored and targos committed Jun 25, 2018
1 parent fefa57a commit cd2b80c
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions lib/internal/process/stdio.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,24 @@ function createWritableStdioStream(fd) {
case 'PIPE':
case 'TCP':
var net = require('net');
stream = new net.Socket({
fd: fd,
readable: false,
writable: true
});

// If fd is already being used for the IPC channel, libuv will return
// an error when trying to use it again. In that case, create the socket
// using the existing handle instead of the fd.
if (process.channel && process.channel.fd === fd) {
stream = new net.Socket({
handle: process.channel,
readable: false,
writable: true
});
} else {
stream = new net.Socket({
fd,
readable: false,
writable: true
});
}

stream._type = 'pipe';
break;

Expand Down

0 comments on commit cd2b80c

Please sign in to comment.