Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e888471

Browse filesBrowse files
bnoordhuisrvagg
authored andcommitted
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: #3574 PR-URL: #3575 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent 4e54dbe commit e888471
Copy full SHA for e888471

File tree

Expand file treeCollapse file tree

2 files changed

+19
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+19
-0
lines changed
Open diff view settings
Collapse file

‎lib/child_process.js‎

Copy file name to clipboardExpand all lines: lib/child_process.js
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@ exports.fork = function(modulePath /*, args, options*/) {
3232

3333
// Prepare arguments for fork:
3434
execArgv = options.execArgv || process.execArgv;
35+
36+
if (execArgv === process.execArgv && process._eval != null) {
37+
const index = execArgv.lastIndexOf(process._eval);
38+
if (index > 0) {
39+
// Remove the -e switch to avoid fork bombing ourselves.
40+
execArgv = execArgv.slice();
41+
execArgv.splice(index - 1, 2);
42+
}
43+
}
44+
3545
args = execArgv.concat([modulePath], args);
3646

3747
// Leave stdin open for the IPC channel. stdout and stderr should be the
Collapse file

‎test/parallel/test-cli-eval.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-cli-eval.js
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ if (module.parent) {
88
var common = require('../common'),
99
assert = require('assert'),
1010
child = require('child_process'),
11+
path = require('path'),
1112
nodejs = '"' + process.execPath + '"';
1213

1314

@@ -75,3 +76,11 @@ child.exec(nodejs + ' --use-strict -p process.execArgv',
7576
function(status, stdout, stderr) {
7677
assert.equal(stdout, "[ '--use-strict', '-p', 'process.execArgv' ]\n");
7778
});
79+
80+
// Regression test for https://github.com/nodejs/node/issues/3574
81+
const emptyFile = path.join(common.fixturesDir, 'empty.js');
82+
child.exec(nodejs + ` -e 'require("child_process").fork("${emptyFile}")'`,
83+
function(status, stdout, stderr) {
84+
assert.equal(stdout, '');
85+
assert.equal(stderr, '');
86+
});

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.