diff options
author | Ben Noordhuis <info@bnoordhuis.nl> | 2015-02-18 05:43:29 +0300 |
---|---|---|
committer | Ben Noordhuis <info@bnoordhuis.nl> | 2015-02-18 17:15:14 +0300 |
commit | b5f25a963cada60ada3230124585ad1fc9a1ad7a (patch) | |
tree | e2e13b38009612eef79a9a976cf5664033d9921d /test | |
parent | a956791f6995f9cfbeb21ffcf129125665bed298 (diff) |
src: ensure that file descriptors 0-2 are valid
Check that stdin, stdout and stderr map to open file descriptors and
remap them to /dev/null if that isn't the case. Protects against
information leaks or worse when io.js is started with closed stdio
file descriptors.
PR-URL: https://github.com/iojs/io.js/pull/875
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Vladimir Kurchatkin <vladimir.kurchatkin@gmail.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/parallel/test-stdio-closed.js | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/test/parallel/test-stdio-closed.js b/test/parallel/test-stdio-closed.js new file mode 100644 index 00000000000..fd081b8c11a --- /dev/null +++ b/test/parallel/test-stdio-closed.js @@ -0,0 +1,24 @@ +var common = require('../common'); +var assert = require('assert'); +var spawn = require('child_process').spawn; + +if (process.platform === 'win32') { + console.log('Skipping test, platform not supported.'); + return; +} + +if (process.argv[2] === 'child') { + process.stdout.write('stdout', function() { + process.stderr.write('stderr', function() { + process.exit(42); + }); + }); +} + +// Run the script in a shell but close stdout and stderr. +var cmd = '"' + process.execPath + '" "' + __filename + '" child 1>&- 2>&-'; +var proc = spawn('/bin/sh', ['-c', cmd], { stdio: 'inherit' }); + +proc.on('exit', common.mustCall(function(exitCode) { + assert.equal(exitCode, 42); +})); |