Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 618caa5

Browse filesBrowse files
evanlucasrvagg
authored andcommitted
child_process: use stdio.fd even if it is 0
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 <me@silverwind.io> Reviewed-By: cjihrig - Colin Ihrig <cjihrig@gmail.com> Reviewed-By: indutny - Fedor Indutny <fedor.indutny@gmail.com>
1 parent 4237373 commit 618caa5
Copy full SHA for 618caa5

File tree

Expand file treeCollapse file tree

2 files changed

+13
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+13
-1
lines changed
Open diff view settings
Collapse file

‎lib/internal/child_process.js‎

Copy file name to clipboardExpand all lines: lib/internal/child_process.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ function _validateStdio(stdio, sync) {
713713
} else if (typeof stdio === 'number' || typeof stdio.fd === 'number') {
714714
acc.push({
715715
type: 'fd',
716-
fd: stdio.fd || stdio
716+
fd: typeof stdio === 'number' ? stdio : stdio.fd
717717
});
718718
} else if (getHandleWrapType(stdio) || getHandleWrapType(stdio.handle) ||
719719
getHandleWrapType(stdio._handle)) {
Collapse file

‎test/parallel/test-child-process-validate-stdio.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-child-process-validate-stdio.js
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,15 @@ var stdio2 = ['ipc', 'ipc', 'ipc'];
2828
assert.throws(function() {
2929
_validateStdio(stdio2, true);
3030
}, /You cannot use IPC with synchronous forks/);
31+
32+
const stdio3 = [process.stdin, process.stdout, process.stderr];
33+
var result = _validateStdio(stdio3, false);
34+
assert.deepStrictEqual(result, {
35+
stdio: [
36+
{ type: 'fd', fd: 0 },
37+
{ type: 'fd', fd: 1 },
38+
{ type: 'fd', fd: 2 }
39+
],
40+
ipc: undefined,
41+
ipcFd: undefined
42+
});

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.