Skip to content

Commit

Permalink
child_process: use stdio.fd even if it is 0
Browse files Browse the repository at this point in the history
Previously, in _validateStdio we were using stdio.fd || stdio. If
stdio.fd was falsy (or 0 in the case of stdin), then the entire stdio
object would be passed which could cause a crash.

Fixes: #2721
PR-URL: #2727
Reviewed-By: silverwind - Roman Reiss <[email protected]>
Reviewed-By: cjihrig - Colin Ihrig <[email protected]>
Reviewed-By: indutny - Fedor Indutny <[email protected]>
  • Loading branch information
evanlucas committed Sep 8, 2015
1 parent 7ee58be commit 3bc7e58
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/internal/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ function _validateStdio(stdio, sync) {
} else if (typeof stdio === 'number' || typeof stdio.fd === 'number') {
acc.push({
type: 'fd',
fd: stdio.fd || stdio
fd: typeof stdio === 'number' ? stdio : stdio.fd
});
} else if (getHandleWrapType(stdio) || getHandleWrapType(stdio.handle) ||
getHandleWrapType(stdio._handle)) {
Expand Down
12 changes: 12 additions & 0 deletions test/parallel/test-child-process-validate-stdio.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,15 @@ var stdio2 = ['ipc', 'ipc', 'ipc'];
assert.throws(function() {
_validateStdio(stdio2, true);
}, /You cannot use IPC with synchronous forks/);

const stdio3 = [process.stdin, process.stdout, process.stderr];
var result = _validateStdio(stdio3, false);
assert.deepStrictEqual(result, {
stdio: [
{ type: 'fd', fd: 0 },
{ type: 'fd', fd: 1 },
{ type: 'fd', fd: 2 }
],
ipc: undefined,
ipcFd: undefined
});

0 comments on commit 3bc7e58

Please sign in to comment.