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 9bb1024

Browse filesBrowse files
robertchirasevanlucas
authored andcommitted
child_process: Check stderr before accessing it
If something bad happens in spawnSync, stderr might be null. Therefore, we have to check it before using it, so we won't mask the actual exception. PR-URL: #6877 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Robert Jefe Lindstädt <robert.lindstaedt@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
1 parent 72fc4eb commit 9bb1024
Copy full SHA for 9bb1024

File tree

Expand file treeCollapse file tree

2 files changed

+14
-2
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+14
-2
lines changed
Open diff view settings
Collapse file

‎lib/child_process.js‎

Copy file name to clipboardExpand all lines: lib/child_process.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ function execFileSync(/*command, args, options*/) {
489489

490490
var ret = spawnSync(opts.file, opts.args.slice(1), opts.options);
491491

492-
if (inheritStderr)
492+
if (inheritStderr && ret.stderr)
493493
process.stderr.write(ret.stderr);
494494

495495
var err = checkExecSyncError(ret);
@@ -509,7 +509,7 @@ function execSync(command /*, options*/) {
509509
var ret = spawnSync(opts.file, opts.options);
510510
ret.cmd = command;
511511

512-
if (inheritStderr)
512+
if (inheritStderr && ret.stderr)
513513
process.stderr.write(ret.stderr);
514514

515515
var err = checkExecSyncError(ret);
Collapse file

‎test/sequential/test-child-process-execsync.js‎

Copy file name to clipboardExpand all lines: test/sequential/test-child-process-execsync.js
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@ var start = Date.now();
1212
var err;
1313
var caught = false;
1414

15+
// Verify that stderr is not accessed when a bad shell is used
16+
assert.throws(
17+
function() { execSync('exit -1', {shell: 'bad_shell'}); },
18+
/spawnSync bad_shell ENOENT/,
19+
'execSync did not throw the expected exception!'
20+
);
21+
assert.throws(
22+
function() { execFileSync('exit -1', {shell: 'bad_shell'}); },
23+
/spawnSync bad_shell ENOENT/,
24+
'execFileSync did not throw the expected exception!'
25+
);
26+
1527
try {
1628
var cmd = `"${process.execPath}" -e "setTimeout(function(){}, ${SLEEP});"`;
1729
var ret = execSync(cmd, {timeout: TIMER});

0 commit comments

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