child_process: do not access stderr when stdio set to 'ignore'

Currently, checkExecSyncError() attempts to access the contents
of stderr. When stdio is set to 'ignore', this causes a crash.
This commit adds a check on the access of stderr. Closes #7966.

Signed-off-by: Fedor Indutny <fedor@indutny.com>
This commit is contained in:
cjihrig 2014-07-19 22:35:07 -04:00 committed by Fedor Indutny
parent 2f0017aa53
commit ea89fdfec4
2 changed files with 11 additions and 4 deletions

View File

@ -1323,10 +1323,10 @@ function checkExecSyncError(ret) {
ret.error = null;
if (!err) {
var cmd = ret.cmd ? ret.cmd : ret.args.join(' ');
err = new Error(util.format('Command failed: %s\n%s',
cmd,
ret.stderr.toString()));
var msg = 'Command failed: ' +
(ret.cmd ? ret.cmd : ret.args.join(' ')) +
(ret.stderr ? '\n' + ret.stderr.toString() : '');
err = new Error(msg);
}
util._extend(err, ret);

View File

@ -96,3 +96,10 @@ assert.strictEqual(ret, msg + '\n', 'execFileSync encoding result should match')
assert.strictEqual(response.toString().trim(), cwd);
})();
// Verify that stderr is not accessed when stdio = 'ignore' - GH #7966
(function() {
assert.throws(function() {
execSync('exit -1', {stdio: 'ignore'});
}, /Command failed: exit -1/);
})();