mirror of https://github.com/nodejs/node.git
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: https://github.com/nodejs/node/pull/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>
This commit is contained in:
parent
257a866918
commit
765de1ae11
|
@ -494,7 +494,7 @@ function execFileSync(/*command, args, options*/) {
|
|||
|
||||
var ret = spawnSync(opts.file, opts.args.slice(1), opts.options);
|
||||
|
||||
if (inheritStderr)
|
||||
if (inheritStderr && ret.stderr)
|
||||
process.stderr.write(ret.stderr);
|
||||
|
||||
var err = checkExecSyncError(ret);
|
||||
|
@ -514,7 +514,7 @@ function execSync(command /*, options*/) {
|
|||
var ret = spawnSync(opts.file, opts.options);
|
||||
ret.cmd = command;
|
||||
|
||||
if (inheritStderr)
|
||||
if (inheritStderr && ret.stderr)
|
||||
process.stderr.write(ret.stderr);
|
||||
|
||||
var err = checkExecSyncError(ret);
|
||||
|
|
|
@ -12,6 +12,18 @@ var start = Date.now();
|
|||
var err;
|
||||
var caught = false;
|
||||
|
||||
// Verify that stderr is not accessed when a bad shell is used
|
||||
assert.throws(
|
||||
function() { execSync('exit -1', {shell: 'bad_shell'}); },
|
||||
/spawnSync bad_shell ENOENT/,
|
||||
'execSync did not throw the expected exception!'
|
||||
);
|
||||
assert.throws(
|
||||
function() { execFileSync('exit -1', {shell: 'bad_shell'}); },
|
||||
/spawnSync bad_shell ENOENT/,
|
||||
'execFileSync did not throw the expected exception!'
|
||||
);
|
||||
|
||||
try {
|
||||
var cmd = `"${process.execPath}" -e "setTimeout(function(){}, ${SLEEP});"`;
|
||||
var ret = execSync(cmd, {timeout: TIMER});
|
||||
|
|
Loading…
Reference in New Issue