child_process: don't fork bomb ourselves from -e
Remove the `-e` argument from process.execArgv in child_process.fork() to keep `node -e 'require("child_process").fork("empty.js")'` from spawning itself recursively. Fixes: https://github.com/nodejs/node/issues/3574 PR-URL: https://github.com/nodejs/node/pull/3575 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
This commit is contained in:
parent
6b0c906e6b
commit
57bce60da3
@ -32,6 +32,16 @@ exports.fork = function(modulePath /*, args, options*/) {
|
||||
|
||||
// Prepare arguments for fork:
|
||||
execArgv = options.execArgv || process.execArgv;
|
||||
|
||||
if (execArgv === process.execArgv && process._eval != null) {
|
||||
const index = execArgv.lastIndexOf(process._eval);
|
||||
if (index > 0) {
|
||||
// Remove the -e switch to avoid fork bombing ourselves.
|
||||
execArgv = execArgv.slice();
|
||||
execArgv.splice(index - 1, 2);
|
||||
}
|
||||
}
|
||||
|
||||
args = execArgv.concat([modulePath], args);
|
||||
|
||||
// Leave stdin open for the IPC channel. stdout and stderr should be the
|
||||
|
@ -8,6 +8,7 @@ if (module.parent) {
|
||||
var common = require('../common'),
|
||||
assert = require('assert'),
|
||||
child = require('child_process'),
|
||||
path = require('path'),
|
||||
nodejs = '"' + process.execPath + '"';
|
||||
|
||||
|
||||
@ -75,3 +76,11 @@ child.exec(nodejs + ' --use-strict -p process.execArgv',
|
||||
function(status, stdout, stderr) {
|
||||
assert.equal(stdout, "[ '--use-strict', '-p', 'process.execArgv' ]\n");
|
||||
});
|
||||
|
||||
// Regression test for https://github.com/nodejs/node/issues/3574
|
||||
const emptyFile = path.join(common.fixturesDir, 'empty.js');
|
||||
child.exec(nodejs + ` -e 'require("child_process").fork("${emptyFile}")'`,
|
||||
function(status, stdout, stderr) {
|
||||
assert.equal(stdout, '');
|
||||
assert.equal(stderr, '');
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user