Skip to content

Commit 618caa5

Browse 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

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

‎lib/internal/child_process.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ function _validateStdio(stdio, sync) {
713713
}elseif(typeofstdio==='number'||typeofstdio.fd==='number'){
714714
acc.push({
715715
type: 'fd',
716-
fd: stdio.fd||stdio
716+
fd: typeofstdio==='number' ? stdio : stdio.fd
717717
});
718718
}elseif(getHandleWrapType(stdio)||getHandleWrapType(stdio.handle)||
719719
getHandleWrapType(stdio._handle)){

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

Lines 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
},/YoucannotuseIPCwithsynchronousforks/);
31+
32+
conststdio3=[process.stdin,process.stdout,process.stderr];
33+
varresult=_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)