Browse Source

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>
archived-io.js-v0.10
cjihrig 11 years ago
committed by Fedor Indutny
parent
commit
ea89fdfec4
  1. 8
      lib/child_process.js
  2. 7
      test/simple/test-child-process-execsync.js

8
lib/child_process.js

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

7
test/simple/test-child-process-execsync.js

@ -96,3 +96,10 @@ assert.strictEqual(ret, msg + '\n', 'execFileSync encoding result should match')
assert.strictEqual(response.toString().trim(), cwd); 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/);
})();

Loading…
Cancel
Save