From 618caa5de0d8f298181c0b9d6fd3b4b9c93ca4a5 Mon Sep 17 00:00:00 2001 From: Evan Lucas Date: Mon, 7 Sep 2015 12:25:25 -0500 Subject: [PATCH] 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: https://github.com/nodejs/node/issues/2721 PR-URL: https://github.com/nodejs/node/pull/2727 Reviewed-By: silverwind - Roman Reiss Reviewed-By: cjihrig - Colin Ihrig Reviewed-By: indutny - Fedor Indutny --- lib/internal/child_process.js | 2 +- test/parallel/test-child-process-validate-stdio.js | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/internal/child_process.js b/lib/internal/child_process.js index c6bb41ffdeb544..4a97502cca6861 100644 --- a/lib/internal/child_process.js +++ b/lib/internal/child_process.js @@ -713,7 +713,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)) { diff --git a/test/parallel/test-child-process-validate-stdio.js b/test/parallel/test-child-process-validate-stdio.js index aba43551e82b44..289323002da4bd 100644 --- a/test/parallel/test-child-process-validate-stdio.js +++ b/test/parallel/test-child-process-validate-stdio.js @@ -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 +});